网格项中包含的内联文本不会用省略号截断

时间:2019-07-18 12:00:31

标签: html css overflow

我似乎无法显示省略号。文本将自动换行到下一行。

text {
   display: inline;
   overflow: hidden;
   text-align: center;
   text-overflow: ellipsis;
}

grid {
   width: 200px;
   height: 3em;
   border: 1px solid #000000ff;
   display: grid;
   grid-template-columns: 1fr;
}
<grid><text>This text should display an ellipsis instead of wrapping!</text></grid>

2 个答案:

答案 0 :(得分:1)

white-space: nowrap;添加到text

text {
   display: inline;
   overflow: hidden;
   text-align: center;
   text-overflow: ellipsis;
   white-space: nowrap;
}

grid {
   width: 200px;
   height: 3em;
   border: 1px solid #000000ff;
   display: grid;
   grid-template-columns: 1fr;
}
<grid><text>This text should display an ellipsis instead of wrapping!</text></grid>

答案 1 :(得分:1)

请为文本应用nowrap的CSS,如下所示:

text {
       display: inline;
       overflow: hidden;
       text-align: center;
       white-space: nowrap;
       text-overflow: ellipsis;
    }
    
    grid {
       width: 200px;
       height: 3em;
       border: 1px solid #000000ff;
       display: grid;
       grid-template-columns: 1fr;
    }
<grid><text>This text should display an ellipsis instead of wrapping!</text></grid>