Home > Web Front-end > CSS Tutorial > 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
Release: 2024-10-26 12:06:02
Original
930 people have browsed it

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>
Copy after login
<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>
Copy after login

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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template