Html 如何使用;文本溢出:省略号“;使用标签元素?
我有一个需要添加省略号的标签,但我无法让它工作:Html 如何使用;文本溢出:省略号“;使用标签元素?,html,css,label,Html,Css,Label,我有一个需要添加省略号的标签,但我无法让它工作: <label id="div2">This is some long text that will not fit in the box</label> label#div2 { white-space: nowrap; width: 30px; overflow: hidden; text-overflow: ellipsis; border: 1px solid #000
<label id="div2">This is some long text that will not fit in the box</label>
label#div2 {
white-space: nowrap;
width: 30px;
overflow: hidden;
text-overflow: ellipsis;
border: 1px solid #000000;
}
这是一些无法放入框中的长文本
标签#第2部分{
空白:nowrap;
宽度:30px;
溢出:隐藏;
文本溢出:省略号;
边框:1px实心#000000;
}
要隐藏元素中的溢出,该元素需要为块级别。但您可能不希望内联标签是块级别的,因为这可能会导致其他问题。所以只需将其设置为
内联块
:
label#cats {
white-space: nowrap;
width: 30px;
overflow: hidden;
text-overflow: ellipsis;
border: 1px solid #000000;
display: inline-block;
}
jsiddle:需要
display:block
或inline block
才能工作,因为默认情况下标签是内联元素,省略号仅在块级元素上工作。