Summary and Comparison of CSS Mainstream Layouts (2) Vertical Center Alignment
Summarize the different implementations of vertical center alignment in several mainstream layouts and the comparisons between them.
Father
Code
1 |
|
Principle
vertical-align
CSS 的属性 vertical-align
用来指定行内元素(inline)或表格单元格(table-cell)元素的垂直对齐方式。
Note that’vertical-align 'only works for inline elements and table cell elements: it cannot be used for vertical alignment块级元素。
You can see the specific value of vertical-align.MDN, just to mention one point here, that is, for inline elements and table cells, their value ranges are not exactly the same, even if the same value will have different meanings.
display
This property was introduced in the previous blog, this time we are using its table-cell value
This value will make the current element behave like a td. The content of td can be centered text or vertically centered.
Advantages
Good compatibility
Disadvantage
Vertical-align is inherited
子posititon:absolute
Code
1 |
|
Principle, Advantages, Disadvantages
You can check mine for this principle.上一篇博客The second plan of the centered text is the same.