这个方法只能将单行文本置中。只需要简单地把 line-height 设置为那个对象的 height 值就可以使文本居中了。
<div id="content"> Content here</div>
#content { height: 100px; line-height: 100px; }
优点:
适用于所有浏览器无足够空间时不会被截断
缺点:
只对文本有效(块级元素无效)多行时,断词比较糟糕
本文共 249 字,大约阅读时间需要 1 分钟。
这个方法只能将单行文本置中。只需要简单地把 line-height 设置为那个对象的 height 值就可以使文本居中了。
<div id="content"> Content here</div>
#content { height: 100px; line-height: 100px; }
优点:
适用于所有浏览器无足够空间时不会被截断
缺点:
只对文本有效(块级元素无效)多行时,断词比较糟糕
转载于:https://my.oschina.net/u/2437172/blog/647085