Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use css to achieve vertical centering

Shulou Source: shulou.com Published: 2022-06-01 03:09:09 10月01日 Update

This article mainly shows you "how to use css to achieve vertical center", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use css to achieve vertical center" this article.

Suppose this scenario is given now:

DEMO

The length of the content in the class='child' div is not certain, and now you need to implement the center of the div.

Vertically centered 1 display: table-cell

You can center elements of different heights vertically.

.parent {display:table-cell; vertical-align:middle;} 2 position: absolute.parent {position:relative;} .child {position:absolute; top:50%; / * reference is the parent container * / transform:translateY (- 50%); / * the percentage reference is itself * /} 3 display: flex

Only compatible with IE10+

Parent {display:flex; align-items:center;} / * or * / .child {margin:0 auto;} is all the content of the article "how to use css to achieve vertical centering". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Content articles references learning help different elements can make scene container easy to understand more organization percentage percentage knowledge editing industry information information channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Huawei MySQL Shulou Information MariaDB