CSS:如果大于两行,文本溢出省略号,这可能吗?

San*_*ndy 3 css

我有一个宽度为 300 像素、高度为 20 像素的 div,文本在其中随机更改。我只想在溢出 2 行时显示省略号,否则仅使用 CSS。

http://jsfiddle.net/7BXtr/272/

HTML:

<div id="container">
            <div class="box">

        <div class="text-body">
            <div class="text-inner">This is the text description of the item.
                It can flow onto more than 2 lines, too,
                if there is room for it, but otherwise
                should only show 1 line.
            </div>
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS:

#container {
    width: 104px;
}
.box {

    max-height: 40px;
    overflow: hidden;

    border: solid 1px red;
    position: relative;
}
.box:after {
    content: '...';
    position: absolute;
    left: 84px;
    bottom: 0;
}
.text-body {
    position: relative;
}
.text-body:before {
    content: '';
    position: absolute;
    left: 80px;
    top: 14px;
    width: 12px;
    height: 2px;
    background: white;
}
.text-inner {
    width: 90px;
    padding-right: 10px;
}
Run Code Online (Sandbox Code Playgroud)

Pin*_*nal 6

您可以有一个大于一行的文本溢出省略号,仅适用于 Webkit,其他供应商尚不支持

这是一个带有椭圆示例的三行文本示例

.three-line-block {
    line-height: 15px; //for not webkit browser
    max-height: 45px; //for not webkit browser
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}
Run Code Online (Sandbox Code Playgroud)