Home  >  Article  >  Web Front-end  >  Why is Button Text Vertically Centered by Default, but Div Text Isn\'t?

Why is Button Text Vertically Centered by Default, but Div Text Isn\'t?

Susan Sarandon
Susan SarandonOriginal
2024-10-26 12:06:02837browse

Why is Button Text Vertically Centered by Default, but Div Text Isn't?

Understanding Button Text Vertical Alignment

Consider the following HTML markup and CSS styles:

<code class="html"><button class="button">Some Text</button>
<div class="button">Some Text</div></code>
<code class="css">.button {
  background: darkgrey;
  height: 40px;
  border: 2px solid grey;
  width: 100%;
  box-sizing: border-box;
  font-size: 14px;
  font-family: helvetica;
  text-align: center;
  margin-bottom: 20px;
}</code>

When you apply these styles, you notice that the text within the