这是我的代码:
<ul class="results">
<li class="item"> <span class="title"><a href="item.html" target="_blank">The numbers in the table specify the first browser version that fully supports the property</a></span><span class="place">Place</span>
</li>
<li class="item"> <span class="title"><a href="item.html" target="_blank">The numbers in the table specify the first browser version that fully supports the property</a></span><span class="place">Place</span>
</li>
</ul>
我正在使用css:
.results {text-overflow: ellipsis;}
然而,它似乎对我的内容不起作用,只是正常溢出。谁能告诉我哪里出错了?
答案 0 :(得分:4)
您必须将text-overflow:ellipsis
应用于.item
,而text-overflow:ellipsis
不能单独应用。
此属性仅影响溢出块的内容 容器元素在其内联进展方向(不是文本 例如,在盒子的底部溢出。文字可能会溢出 当它被阻止包裹时(例如,由于'
white-space:nowrap
') 或者单个词太长而不适合。此CSS属性不会强制发生溢出;这样做 要使文本溢出应用,作者必须应用一些 元素的其他属性,例如将
overflow
设置为hidden
。
.item {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap
}
<ul class="results">
<li class="item">
<span class="title">
<a href="item.html" target="_blank">The numbers in the table specify the first browser version that fully supports the property The numbers in the table specify the first browser version that fully supports the property The numbers in the table specify the first browser version that fully supports the property The numbers in the table specify the first browser version that fully supports the property The numbers in the table specify the first browser version that fully supports the property </a>
</span>
<span class="place">Place</span>
</li>
<li class="item">
<span class="title">
<a href="item.html" target="_blank">The numbers in the table specify the first browser version that fully supports the property The numbers in the table specify the first browser version that fully supports the property The numbers in the table specify the first browser version that fully supports the property The numbers in the table specify the first browser version that fully supports the property The numbers in the table specify the first browser version that fully supports the property The numbers in the table specify the first browser version that fully supports the property The numbers in the table specify the first browser version that fully supports the property The numbers in the table specify the first browser version that fully supports the property</a>
</span>
<span class="place">Place</span>
</li>
</ul>
width
添加.item
,如下所示
.item {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
width: 150px
}
<ul class="results">
<li class="item">
<span class="title">
<a href="item.html" target="_blank">The numbers in the table specify the first browser version that fully supports the property The numbers in the table specify the first browser version that fully supports the property The numbers in the table specify the first browser version that fully supports the property The numbers in the table specify the first browser version that fully supports the property The numbers in the table specify the first browser version that fully supports the property </a>
</span>
<span class="place">Place</span>
</li>
<li class="item">
<span class="title">
<a href="item.html" target="_blank">The numbers in the table specify the first browser version that fully supports the property The numbers in the table specify the first browser version that fully supports the property The numbers in the table specify the first browser version that fully supports the property The numbers in the table specify the first browser version that fully supports the property The numbers in the table specify the first browser version that fully supports the property The numbers in the table specify the first browser version that fully supports the property The numbers in the table specify the first browser version that fully supports the property The numbers in the table specify the first browser version that fully supports the property</a>
</span>
<span class="place">Place</span>
</li>
</ul>
.place
始终显示,因此你需要将display:inline-block
添加到.title
(因为span
的初始值为{{1} }})
inline
.title {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
display: inline-block;
width: 150px
}
答案 1 :(得分:1)
这是代码。
.results .item {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
<ul class="results">
<li class="item"> <span class="title"><a href="item.html" target="_blank">The numbers in the table specify the first browser version that fully supports the property</a></span><span class="place">Place</span>
</li>
<li class="item"> <span class="title"><a href="item.html" target="_blank">The numbers in the table specify the first browser version that fully supports the property</a></span><span class="place">Place</span>
</li>
</ul>