2016-03-09 18 views
0

我試圖使文本適合容器的一行,即使標題太長。如何自動將文本放入框中即使標題太長

<div id="container" style=" 
    width:360px; 
    margin:0 auto; 
    background:#f7f7f7; 
    box-shadow:0 0 3px rgba(0,0,0, 0.1)"> 
    <h5 style=" 
    background:#2980b9; 
    color:white; 
    margin:0 
    padding:10px 20px;">popular</h5> 
    <ul style=" 
    list-style:none; 
    margin:0; 
    padding:0;"> 
    {% for x in topStory %} 
<a href='{{ x.get_absolute_url }}'><li class="unique">{{x.title}}</li></a> 
    {% endfor %} 
    </ul> 
    </div> 

有沒有辦法做到這一點?或者每次我製作標題時都必須小心。

回答

2
white-space: nowrap; 

在CSS將其約束到一條線。然後,你可以做的東西,如:

overflow: hidden; 

隱藏它和可選

text-overflow: ellipsis; 

,使瀏覽器中的「...」放在最後,當它的剪輯。

相關問題