2013-10-29 91 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底部的高度。 –