twitter-bootstrap - 如何在 Bootstrap 列中使用文本溢出?

标签 twitter-bootstrap css twitter-bootstrap-3 overflow

假设我有一行高度固定,我在它的列中插入了一些文本。如果太长,我想将其截断,并在行尾添加三个点,如下所示:

enter image description here

我在我的行中为此使用了 text-overflow: ellipsis; 属性,但无法使其正常工作。

enter image description here

JsFiddle

我做错了什么?

HTML

<div class="container">
  <div class="row text">    
    <div class="col-xs-4" style="border: solid">
 Some really long text!  Some really long text!  Some really long text!  Some really long text! The end! Some really long text! The end! Some really long text! The end! Some really long text! The end!
    </div>
  </div>        
</div>

CSS

.row {
    margin: 2px 0;
}

.text {
    word-wrap: break-word;
    height: 50px;
    text-overflow: ellipsis;
}

最佳答案

如果你想用 css 做这个,那么试试下面的代码:

HTML:

<div class="container">
  <div class="row">    
    <div class="col-xs-4" style="border: solid">
        <div class="text">
            Some really long text!  Some really long text!  Some really long text!  Some really long text! The end! Some really long text! The end! Some really long text! The end! Some really long text! The end!
        </div>
    </div>
  </div>        
</div>

CSS:

.row {
    margin: 2px 0;
}

.text {
    display: block;
    display: -webkit-box;
    max-width: 400px;
    height: 50px;
    margin: 0 auto;
    line-height: 1.2;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

这里是 jsfiddle

了解 css 中的线条拍手 Line Clamping

关于twitter-bootstrap - 如何在 Bootstrap 列中使用文本溢出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33165066/

相关文章:

javascript - jQuery slider 在 Chrome 上不起作用(有间隔)

css - 无法重置-webkit-filter : in inner div

html - 用于大屏幕标题的 Bootstrap 3 网格列

html - Bootstrap Grid系统连续多个div

javascript - bootstrapValidator ajax请求,防止提交后关闭 Bootstrap 模式

jquery - 推特 Bootstrap 导航 : need to create scroll bar when not collapsing

css - 对齐两个 DIV 并使用整个页面宽度

javascript - jQuery:横向滚动的正文背景?

html - 为什么我的 bootstrap inputs 比他们的 parent div 大

css - 如何在 Jumbotron Bootstrap 3 中更改字体粗细