Centering with pseudo element
suggest changeHTML:
<div class="wrapper">
<div class="content"></div>
</div>
CSS:
.wrapper{
min-height: 600px;
}
.wrapper:before{
content: "";
display: inline-block;
height: 100%;
vertical-align: middle;
}
.content {
display: inline-block;
height: 80px;
vertical-align: middle;
}
This method is best used when a variable-height .content is centered inside .wrapper, and .wrapper should grow once .content exceeds the wrapper’s min-height. Percentage heights need a definite containing-block height; with only min-height, some browsers treat the pseudo-element’s height: 100% as auto.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents