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/column-gap/index.html | 203 ++++++++++++++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 files/zh-cn/web/css/column-gap/index.html (limited to 'files/zh-cn/web/css/column-gap/index.html') diff --git a/files/zh-cn/web/css/column-gap/index.html b/files/zh-cn/web/css/column-gap/index.html new file mode 100644 index 0000000000..14d8e10dbd --- /dev/null +++ b/files/zh-cn/web/css/column-gap/index.html @@ -0,0 +1,203 @@ +--- +title: column-gap +slug: Web/CSS/column-gap +translation_of: Web/CSS/column-gap +--- +
{{CSSRef}}
+ +

column-gap 该 CSS 属性用来设置元素列之间的间隔 ({{glossary("gutters","gutter")}}) 大小。

+ +
{{EmbedInteractiveExample("pages/css/column-gap.html")}}
+ +
{{EmbedInteractiveExample("pages/css/grid-column-gap.html")}}
+ + + +

column-gap一开始是 Multi-column 布局 下的特有属性,后来在其他布局中也使用这个属性。如 Box Alignment 中的表述,该属性已经在Multi-column(多列布局)、Flexible Box(弹性盒子)以及 Grid layouts(网格布局)中使用。

+ +
+

CSS Grid Layout 起初是用 grid-gap 属性来定义的,目前逐渐被 gap 替代。但是,为了兼容那些不支持 gap 属性的浏览器,你需要像上面的例子一样使用带有前缀的属性。

+
+ +

语法

+ +
/* Keyword value */
+column-gap: normal;
+
+/* <length> values */
+column-gap: 3px;
+column-gap: 2.5em;
+
+/* <percentage> value */
+column-gap: 3%;
+
+/* Global values */
+column-gap: inherit;
+column-gap: initial;
+column-gap: unset;
+ +

 column-gap 属性有以下值来表示。

+ +

取值

+ +

normal

+ +
+
表示列之间的间隔宽度。在 多列布局 时默认间隔为1em,其他类型布局默认间隔为 0。
+
{{cssxref("<length>")}}
+
用{{cssxref("<length>")}}来定义列之间的间隔大小。而且 {{cssxref("<length>")}} 值必须是非负数的。
+
{{cssxref("<percentage>")}}
+
用{{cssxref("<percentage>")}}(百分比)来定义列之间的间隔大小。同样的,{{cssxref("<percentage>")}} 值也必须是非负数的。
+
+ +

正式语法

+ +
{{csssyntax}}
+ +

示例

+ +

Flex布局

+ +

{{SeeCompatTable}}

+ +

HTML

+ +
<div id="flexbox">
+  <div></div>
+  <div></div>
+  <div></div>
+</div>
+
+ +

CSS

+ +
#flexbox {
+  display: flex;
+  height: 100px;
+  column-gap: 20px;
+}
+
+#flexbox > div {
+  background-color: lime;
+  flex: auto;
+}
+
+ +

结果

+ +

{{EmbedLiveSample('Flex布局', "auto", "120px")}}

+ +

Grid布局

+ +

HTML

+ +
<div id="grid">
+  <div></div>
+  <div></div>
+  <div></div>
+</div>
+ +

CSS

+ + + +
#grid {
+  display: grid;
+  height: 100px;
+  grid-template-columns: repeat(3, 1fr);
+  grid-template-rows: 100px;
+  column-gap: 20px;
+}
+
+#grid > div {
+  background-color: lime;
+}
+
+ +

结果

+ +

{{EmbedLiveSample("Grid布局", "auto", "120px")}}

+ +

Multi-column布局

+ +

HTML

+ +
<p class="content-box">
+  This is some multi-column text with a 40px column
+  gap created with the CSS `column-gap` property.
+  Don't you think that's fun and exciting? I sure do!
+</p>
+
+ +

CSS

+ +
.content-box {
+  column-count: 3;
+  column-gap: 40px;
+}
+
+ +

结果

+ +

{{EmbedLiveSample("Multi-column布局", "auto", "120px")}}

+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
规范状态备注
{{SpecName("CSS3 Box Alignment", "#column-row-gap", "column-gap")}}{{Spec2("CSS3 Box Alignment")}}在弹性布局和网格布局中应用
{{SpecName("CSS3 Grid", "#gutters", "column-gap")}}{{Spec2("CSS3 Grid")}}描述在网格布局中的作用
{{SpecName("CSS3 Multicol", "#column-gap", "column-gap")}}{{Spec2("CSS3 Multicol")}}初始化定义
+ +

{{cssinfo}}

+ +

浏览器兼容性

+ + + +

在 Flex 布局中的兼容性

+ +

{{Compat("css.properties.column-gap.flex_context")}}

+ +

在 Grid 布局中的兼容性

+ +

{{Compat("css.properties.column-gap.grid_context")}}

+ +

在 Multi-column 布局中的兼容性

+ +

{{Compat("css.properties.column-gap.multicol_context")}}

+ +

参见

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