我有一个 div,我需要将其内容垂直居中:
<div draggable="false" id="coffee">Free coffee for all the people who visit my restaurant</div>
#coffee {
line-height: 235px;
width: 300px;
}
div {
position: absolute;
overflow: auto;
text-align: left;
font-size: 23px;
color: rgb(26, 66, 108);
font-family: roboto, Helvetica;
font-style: normal;
font-weight: bold;
-webkit-transition: none;
transition: none;
left: 0px;
top: 67.125px;
height: 234.93749999999997px;
opacity: 1;
}
它通过使用行高来工作,但是在跳转行中,短语太分开了,我需要它不被分开。
这是小提琴链接:http://jsfiddle.net/2Mb39/4/ http://jsfiddle.net/2Mb39/4/
Daniel
您必须添加第二个 div 才能实现此目的。
<div draggable="false" id="coffee" style="position: absolute; overflow: auto; text-align: left; font-size: 23px; color: rgb(26, 66, 108); font-family: roboto, Helvetica; font-style: normal; font-weight: bold; -webkit-transition: none; transition: none; left: 0px; top: 67.125px; height: 234.93749999999997px; opacity: 1;">
<div class="inner">
Free coffee for all the people who visit my restaurant
</div>
</div>
#coffee {
display: table;
width: 300px;
background-color: red;
}
#coffee .inner{
vertical-align: middle;
display: table-cell;
}
例子:http://jsfiddle.net/2Mb39/12/ http://jsfiddle.net/2Mb39/12/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)