I am trying to find the most effective way to align text with a div. I have tried a few things and none seem to work.
.testimonialText {
position: absolute;
left: 15px;
top: 15px;
width: 150px;
height: 309px;
vertical-align: middle;
text-align: center;
font-family: Georgia, "Times New Roman", Times, serif;
font-style: italic;
padding: 1em 0 1em 0;
}
<div class="testimonialText">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
Using css grid did it for me.
Try to embed a table element.
This is another variation of the
div
in adiv
pattern usingcalc()
in CSS.This works, because:
position:absolute
for precise placement of thediv
within adiv
div
because we set it to20px
.calc(50% - 10px)
for 50% - half the height for centering the innerdiv
Not a single answer helped me, try this, add on parent div:
As simple as this, from the docs:
Vertical Centering in CSS
http://www.jakpsatweb.cz/css/css-vertical-center-solution.html
Article summary:
For CSS2 browser one can use
display:table
/display:table-cell
to center content.Sample also available at JSFiddle:
It is possible to merge hacks for old browser (IE6/7) into styles with using
#
to hide styles from newer browsers: