Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何使用;文本溢出:省略号“;使用标签元素?_Html_Css_Label - Fatal编程技术网

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
才能工作,因为默认情况下标签是内联元素,省略号仅在块级元素上工作。