我不知道为什么这个简单的CSS不能工作…

.app a { 高度:18 px; 宽度:140 px; 填充:0; 溢出:隐藏; 位置:相对; Margin: 0 5px 0 5px; text-align:中心; 文字修饰:没有; 文本溢出:省略; 空白:nowrap;} 颜色:# 000; } < div class = "应用" > <a href="">Test Test Test Test Test Test Test</a> . < / div >

应该在第四次“测试”前后切断


当前回答

锚,跨度…标签默认是内联元素,如果内联元素宽度属性不起作用。因此,您必须将元素转换为内联块或块级元素

其他回答

因此,如果您遇到这个问题是因为您在试图让省略号在display: flex容器内工作时遇到了麻烦,请尝试向最外层的容器添加min-width: 0,该容器正在溢出其父容器,即使您已经为它设置了overflow: hidden,并查看这对您来说是如何工作的。

关于这个代码的更多细节和工作示例由aj-foster编写。对我来说完全管用。

包括info后面写的四行,以便省略号起作用

.app a
{
 color: #fff;
 font: bold 15px/18px Arial;
 height: 18px;
 margin: 0 5px 0 5px;
 padding: 0;
 position: relative;
 text-align: center;
 text-decoration: none;
 width: 140px;

 /* 
 Note: The Below 4 Lines are necessary for ellipsis to work.
 */

 display: block;/* Change it as per your requirement. */
 overflow: hidden;
 text-overflow: ellipsis;
 white-space: nowrap;
}

你只需要添加一行css:

.app a {
   display: inline-block;
}

我一直有这个问题,我想要一个解决方案,可以很容易地与动态宽度工作。解决方案使用css网格。 下面是代码的样子:

.parent { 显示:网格; Grid-template-columns: auto 1fr; } .dynamic-width-child { 空白:nowrap;} 文本溢出:省略; 溢出:隐藏; } .fixed-width-child { 空白:nowrap;} } < div class = "父" > < div class = " dynamic-width-child”> iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii asdfhlhlafh; lshd flhsd; lhfaaaaaaaaaaaaaaaaaaaa < / div > < div class = " fixed-width-child”>为什么?zed < / div > < / div >

必须包含

  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;

绝对不能包含

display: inline

应该包含

position: sticky