Home > Web Front-end > CSS Tutorial > Detailed explanation of vertical-align attribute examples in css

Detailed explanation of vertical-align attribute examples in css

零下一度
Release: 2017-04-21 09:27:44
Original
2713 people have browsed it

This article mainly introduces an in-depth understanding of the vertical-align attribute in CSS. The editor thinks it is quite good. Now I will share it with you and give it a reference. Let’s follow the editor and take a look.

1. Why write this article

I saw a question today:

Both p's are set to display: inline-block, which displays normally; but when a block-level element or inline element is added to the second p, the display changes. Why?


<meta charset="utf-8"/>
<style>
p{
    width: 100px;
    height: 100px;
    border:1px solid red;
    display: inline-block;
}
.align{
/*    vertical-align: top;*/
}
</style>
<body>
    <p>
    </p>
    <p class="align">为什么?</p>
</body>
Copy after login

The solution is to add: vertical-align:top to the second p.

I know a little bit about vertical-align and baseline, but I couldn’t answer this question, so I will share my learning summary.

2. What does vertical-align do?

w3c has a piece of relevant information as follows:


##

&#39;vertical-align&#39;
Value:      baseline | sub | super | top | text-top | middle | bottom | text-bottom | <percentage> | <length> | inherit
Initial:      baseline
Applies to:      inline-level and &#39;table-cell&#39; elements
Inherited:      no
Percentages:      refer to the &#39;line-height&#39; of the element itself
Media:      visual
Computed value:      for <percentage> and <length> the absolute length, otherwise as specified
Copy after login

You can see that vertical-align affects inline- Vertical layout of level elements and table-cell elements. According to the MDN description, vertical-align is also applicable to ::first-letter and ::first-line.

Applies to:

inline horizontal elements

inline:,,,< em>,Unknown element

inline-block:(IE8+),
Related labels:
css
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template