Bootstrap 4列表项仅限单行(省略号不起作用)

时间:2018-04-26 11:20:48

标签: css twitter-bootstrap bootstrap-4

我有一张带有列表项的Bootstrap 4卡。我希望每个列表文本只是单行,并占用卡的全宽,否则显示3个点(省略号)或只是用overflow:hidden隐藏它,但它不起作用。

这是问题所在:

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="card">
  <ul class="list-group list-group-flush">
    <li class="list-group-item"><p>Long content ............. Here. Overflow Ellipsis or Hidden not working (This should be 1 line of card width, on all screen sizes, and depending on screen size)</p></li>
    <li class="list-group-item"><p>Second List Item</p></li>
    <li class="list-group-item"><p>Third List Item</p></li>
  </ul>
</div>

3 个答案:

答案 0 :(得分:5)

只需使用Bootstrap 4 text-truncate类..

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="card">
  <ul class="list-group list-group-flush">
    <li class="list-group-item"><p class="text-truncate">Long content ............. Here. Overflow Ellipsis or Hidden not working (This should be 1 line of card width, on all screen sizes, and depending on screen size)</p></li>
    <li class="list-group-item"><p>Second List Item</p></li>
    <li class="list-group-item"><p>Third List Item</p></li>
  </ul>
</div>

Codeply demo

详细了解Bootstrap 4 text utilities

答案 1 :(得分:0)

在li标签内的p标签上使用以下样式

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

答案 2 :(得分:0)

你走了:

p {
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="card">
  <ul class="list-group list-group-flush">
    <li class="list-group-item"><p>Long content ............. Here. Overflow Ellipsis or Hidden not working (This should be 1 line of card width, on all screen sizes, and depending on screen size)</p></li>
    <li class="list-group-item"><p>Second List Item</p></li>
    <li class="list-group-item"><p>Third List Item</p></li>
  </ul>
</div>