我有一個寬度爲300px,高度爲20px的div,文本隨機更改。我只想在用2行溢出時才顯示省略號,否則就只用CSS。CSS:如果大於兩行的文本溢出省略號,有可能嗎?
http://jsfiddle.net/7BXtr/272/
HTML:
<div id="container">
<div class="box">
<div class="text-body">
<div class="text-inner">This is the text description of the item.
It can flow onto more than 2 lines, too,
if there is room for it, but otherwise
should only show 1 line.
</div>
</div>
</div>
</div>
CSS:
#container {
width: 104px;
}
.box {
max-height: 40px;
overflow: hidden;
border: solid 1px red;
position: relative;
}
.box:after {
content: '...';
position: absolute;
left: 84px;
bottom: 0;
}
.text-body {
position: relative;
}
.text-body:before {
content: '';
position: absolute;
left: 80px;
top: 14px;
width: 12px;
height: 2px;
background: white;
}
.text-inner {
width: 90px;
padding-right: 10px;
}
沒有 - 這是不可能的CSS不幸的是,你需要一個JS的解決方案 – SW4