-webkit-line-clamp
CSS property allows limiting of the contents of a
block container
to the specified number of lines.
It only works in combination with the
display
property set to
-webkit-box
or
-webkit-inline-box
和
-webkit-box-orient
property set to
vertical
.
In most cases you will also want to set
overflow
to
hidden
, otherwise the contents won't be clipped but an ellipsis will still be shown after the specified number of lines.
When applied to anchor elements, the truncating can happen in the middle of the text, not necessarily at the end.
注意
: This property was originally implemented in WebKit and has some issues. It got standardized for legacy support. The
CSS Overflow Module Level 3
specification also defines a
line-clamp
property, which is meant to replace this property and avoid its issues.
/* Keyword value */ -webkit-line-clamp: none; /* <integer> values */ -webkit-line-clamp: 3; -webkit-line-clamp: 10; /* Global values */ -webkit-line-clamp: inherit; -webkit-line-clamp: initial; -webkit-line-clamp: unset;
none
This value specifies that the content wonʼt be clamped.
<integer>
This value specifies the number of lines after which the content will be clamped. It must be greater than 0.
| 初始值 |
none
|
|---|---|
| 适用于 | 所有元素 |
| 继承 | no |
| 计算值 | 如指定 |
| 动画类型 | by computed value type |
none | <integer>
<p> In this example the <code>-webkit-line-clamp</code> property is set to <code>3</code>, which means the text is clamped after three lines. An ellipsis will be shown at the point where the text is clamped. </p>
p {
width: 300px;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
CSS Overflow Module Level 3
The definition of '-webkit-line-clamp' in that specification. |
工作草案 | 初始定义 |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
-webkit-line-clamp
|
Chrome 完整支持 6 | Edge 完整支持 17 | Firefox 完整支持 68 | IE 不支持 No | Opera 完整支持 15 | Safari 完整支持 5 | WebView Android 完整支持 ≤37 | Chrome Android 完整支持 18 | Firefox Android 完整支持 68 | Opera Android 完整支持 14 | Safari iOS 完整支持 4.2 | Samsung Internet Android 完整支持 1.0 |
完整支持
不支持
-webkit-border-before
-webkit-box-reflect
-webkit-line-clamp
-webkit-mask-attachment
-webkit-mask-composite
-webkit-mask-position-x
-webkit-mask-position-y
-webkit-mask-repeat-x
-webkit-mask-repeat-y
-webkit-overflow-scrolling
-webkit-tap-highlight-color
-webkit-text-fill-color
-webkit-text-stroke
-webkit-text-stroke-color
-webkit-text-stroke-width
-webkit-touch-callout
box-align
box-direction
box-flex
box-flex-group
box-lines
box-ordinal-group
box-orient
box-pack
overflow
overflow-block
overflow-inline
overflow-x
overflow-y