简体   繁体   English

CSS:如何在高度受限的框中设置文本样式

[英]CSS: How to style text in a box with a limited height

Have the following html that leverages Dust.js: 具有以下利用Dust.js的html:

<div class="box">
    {text}
</div>

I want to style the box div such that, if the text, which is variable, goes longer than 100 pixels in height, it is cut off, so that the box works as a kind of mask for the text in question. 我想对box div进行样式box ,以使如果可变文本的高度超过100像素,则将其截断,以使该box可以用作所讨论文本的一种蒙版。 Setting 设置

.box{
   height: 100px;
}

does not do the trick here. 在这里不解决问题。

Try this: 尝试这个:

.box{
   max-height: 100px;
    overflow:hidden;
}

您可以在CSS3中使用术语max-height ,也可以 white-space:nowrap;

you can use overflow:hidden 您可以使用overflow:hidden

see jsfiddle for example: http://jsfiddle.net/ 例如,请参见jsfiddle: http : //jsfiddle.net/

Try this 尝试这个

.box{
    max-height: 100px;
    text-overflow:ellipsis;
    white-space:nowrap;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM