css3 - text-overflow為何會在li的子標簽a下失效
問題描述
<ul> <li><span>2014-05-28</span><a href='http://www.4tl426be.cn/wenda/news.html'>這不是廣告這不是廣告這不是廣告這不是廣告這不是廣告這不是廣告這不是廣告這不是廣告這不是廣告這不是廣告這不是廣告</a></li></ul>
設(shè)置的CSS如下
li{ overflow: hidden; white-space: nowrap; text-overflow:ellipsis; width: 747px;}
為什么給a設(shè)置同樣的樣式會失效,而li不會
問題解答
回答1:設(shè)置 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設(shè)置的時候,加上display: inline-block;
相關(guān)文章:
1. angular.js - webpack build后的angularjs路由跳轉(zhuǎn)問題2. 數(shù)組按鍵值封裝!3. java - web項目中,用戶登陸信息存儲在session中好 還是cookie中好,取決于什么?4. mysql - navicat 經(jīng)常打開表一直在載入中 也不能關(guān)閉 著急解決5. mysql - 根據(jù)一個字段查找另一個字段重復(fù)的數(shù)據(jù)?并刪除相同的記錄,保留其中一個。6. 單擊登錄按鈕無反應(yīng)7. Mysql取下一條記錄8. mysql - 大部分數(shù)據(jù)沒有行溢出的text字段是否需要拆表9. mysql 新增用戶 主機名設(shè)定 失敗10. mysql儲存json錯誤
