css3 - text-overflow為何會在li的子標簽a下失效
問題描述
<ul> <li><span>2014-05-28</span><a href='http://www.wxshucaidpc.com/wenda/news.html'>這不是廣告這不是廣告這不是廣告這不是廣告這不是廣告這不是廣告這不是廣告這不是廣告這不是廣告這不是廣告這不是廣告</a></li></ul>
設置的CSS如下
li{ overflow: hidden; white-space: nowrap; text-overflow:ellipsis; width: 747px;}
為什么給a設置同樣的樣式會失效,而li不會
問題解答
回答1:設置 a { display: inline-block; } 即可。
Text overflow can only happen on block or inline-block level elements, because the element needs to have a width in order to be overflow-ed. The overflow happens in the direction as determined by the direction property or related attributes. - via: https://css-tricks.com/almanac/properties/t/text-overflow/
回答2:在給a設置的時候,加上display: inline-block;
相關文章:
