How to use css to achieve vertical centering
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!