The div always has a fixed height. The text in it should always be centered. As soon as the text becomes larger than the div, the font-size should become smaller so that the text is centered in the div. The problem is, I can not add different classes to the headings. Has anyone an idea how I can solve this? Do I need javascript? Any help will be appreciated. Thank You.
.fix-height{
height: 60px;
width: 270px;
border: 1px solid #000000;
display: table-cell;
vertical-align: middle;
text-align: center;
}
h2{
font-size: 20px;
}
<div class="fix-height">
<h2>Lorem ipsum dolor sit Lorem ipsum dolor sit</h2>
</div>
<br><br><br><br>
<div class="fix-height">
<h2>Lorem ipsum dolor sit</h2>
</div>
<br><br><br><br>
<div class="fix-height">
<h2>Lorem ipsum dolor sit Lorem ipsum dolor sit Lorem ipsum dolor sit</h2>
</div>