Detailed explanation of vertical-align attribute examples in css

零下一度
Release: 2017-04-21 09:27:44
Original
2618 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?


   

为什么?

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:


##

'vertical-align' Value: baseline | sub | super | top | text-top | middle | bottom | text-bottom |  |  | inherit Initial: baseline Applies to: inline-level and 'table-cell' elements Inherited: no Percentages: refer to the 'line-height' of the element itself Media: visual Computed value: for  and  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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!