: Centering text vertically with CSS How can I vertically center text in an element? For example, from this: to this: I know I can specify the height property on the text and then use position:
How can I vertically center text in an element?
For example, from this:
to this:
I know I can specify the height property on the text and then use
position: absolute;
top: 0;
bottom: 0;
margin: 0;
but I don't want this because the height of the text is variable.
More posts by @Martha945
1 Comments
Sorted by latest first Latest Oldest Best
Check this out: stackoverflow.com/questions/8865458/how-to-align-text-vertically-center-in-div-with-css
HTML:
<div>
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span>
</div>
CSS:
div {
width: 250px;
height: 100px;
line-height: 100px;
text-align: center;
}
span {
display: inline-block;
vertical-align: middle;
line-height: normal;
}
Demo
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.