记录text-overflow的一个坑,下方写法text-overflow无效
li{
list-style: none;
height: 16px;
width:175px;
margin-bottom: 6px;
text-overflow:ellipsis;
white-space: nowrap;
overflow: hidden;
}
a{
color: #666;
}
原因:text-overflow仅对块级元素才有效,li下的a不是块级元素,所以无效,改成以下写法解决
li{
list-style: none;
height: 16px;
width:175px;
margin-bottom: 6px;
}
li a{
color: #666;
display:block;
text-overflow:ellipsis;
white-space: nowrap;
overflow: hidden;
width:175px;
}
a标签使用display改成block或inline-block,但是如果a没有标明具体宽度也text-overflow也无效。