2013-10-29 87 views
0

我想在html中创建一个具有固定大小的div元素。我的问题是,上面的div接收骨干输入文本。文本的大小是未知的,所以每次发送的文本很大时,div的大小自动变化。如何才能显示适合div的预定义边界框的文本的第一个单词?div元素的固定大小

我的CSS代码

.hashTagsCloud { 
max-width: 500px; 
max-height: 400px; 
overflow: hidden; 
} 

和HTML代码:

   <div class= "hashTagsCloud span4 offset1 "> //bootstrap    
       <div id="profiles> //backbone view 
        <script id="profileTemplate" type="text/template">//backbone template 
        </script> 
       </div> 
       </div> 

我拿数据和的getElementById。

+1

您是否在寻找'height','width'和组合['溢出:隐藏;'(https://developer.mozilla.org/en-US/docs/Web/CSS/溢出)? – Sirko

回答

1

可以使用overflow: hidden;财产,理所当然地认为你设置的宽度并已在div上的高度。

<style type='text/css'> 
.text { 
    width: 100px; 
    height: 18px; 
    overflow: hidden; 
    white-space: pre-line; /* breaks up the text on spaces before hiding */ 
} 
</style> 
<div class='text'>some really really really long text</div> 
1

在CSS DIV元素,你可以使用

overflow: hidden 
1

你可以从这个text-overflow: ellipsis; CSS的使用,检查this

+0

在我的div中,我已经获得了400px的高度,所以它适合几行文字。我想要空白:nowrap;只发生在我的div底部的高度。 –