div总是有固定的高度。其中的文字应始终居中。只要文本大于div,字体大小应该变小,以便文本以div为中心。 问题是,我无法为标题添加不同的类。 有没有人可以解决这个问题?我需要JavaScript吗? 任何帮助将不胜感激。谢谢。固定高度div中的文字,文字无间隔
.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>
文本你应该去看一下这:http://stackoverflow.com/questions/16056591/font-scaling-based-on-width-of-container – Fabio