From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/css/-webkit-line-clamp/index.html | 97 +++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 files/zh-cn/web/css/-webkit-line-clamp/index.html (limited to 'files/zh-cn/web/css/-webkit-line-clamp') diff --git a/files/zh-cn/web/css/-webkit-line-clamp/index.html b/files/zh-cn/web/css/-webkit-line-clamp/index.html new file mode 100644 index 0000000000..ec8c7b0d89 --- /dev/null +++ b/files/zh-cn/web/css/-webkit-line-clamp/index.html @@ -0,0 +1,97 @@ +--- +title: '-webkit-line-clamp' +slug: Web/CSS/-webkit-line-clamp +translation_of: Web/CSS/-webkit-line-clamp +--- +

{{CSSRef}}

+ +

-webkit-line-clamp CSS 属性 可以把 {{Glossary("块容器")}} 中的内容限制为指定的行数.

+ +

它只有在 {{cssxref("display")}} 属性设置成 -webkit-box 或者 -webkit-inline-box 并且 {{cssxref("-webkit-box-orient")}} 属性设置成 vertical时才有效果

+ +

在大部分情况下,也需要设置 {{cssxref("overflow")}} 属性为 hidden, 否则,里面的内容不会被裁减,并且在内容显示为指定行数后还会显示省略号(ellipsis ).

+ +

当他应用于锚(anchor)元素时,截取动作可以发生在文本中间,而不必在末尾.

+ +
+

注意: 此属性在WebKit 中已经实现,但有一些问题.他是旧标准的一种支持.CSS Overflow Module Level 3 规范还定义了一个 {{cssxref("line-clamp")}} 属性, 用来代替此属性且避免一些问题.

+
+ +

语法

+ +
/* 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
+
这个值表明内容显示不会被限制.
+
{{cssxref("integer")}}
+
这个值表明内容显示了多少行之后会被限制.必须大于0.
+
+ +

例子

+ +

HTML

+ +
<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>
+ +

CSS

+ +
p {
+  width: 300px;
+  display: -webkit-box;
+  -webkit-box-orient: vertical;
+  -webkit-line-clamp: 3;
+  overflow: hidden;
+}
+ +

结果

+ +

{{EmbedLiveSample("例子", "100%", "100")}}

+ +

规范

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName("CSS3 Overflow", "#propdef--webkit-line-clamp", "-webkit-line-clamp")}}{{Spec2("CSS3 Overflow")}}Initial definition
+ +

{{cssinfo}}

+ +

浏览器兼容性

+ + + +

{{Compat("css.properties.-webkit-line-clamp")}}

+ +

See also

+ + -- cgit v1.2.3-54-g00ecf