column-gap
CSS
property sets the size of the gap (
gutter
) between an element's columns.
Initially a part of
Multi-column Layout
, the definition of
column-gap
has been broadened to include multiple layout methods. Now specified in
Box Alignment
, it may be used in Multi-column, Flexible Box, and Grid layouts.
CSS 栅格布局
initially defined the
grid-column-gap
property. This prefixed property is being replaced by
column-gap
. However, in order to support browsers that implemented
grid-column-gap
and not
column-gap
for grid, you will need to use the prefixed property.
/* 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
property is specified as one of the values listed below.
normal
1em
. For all other layout types it is 0.
<length>
<length>
。
<length>
property's value must be non-negative.
<percentage>
<percentage>
。
<percentage>
property's value must be non-negative.
| 初始值 |
normal
|
|---|---|
| 适用于 | multi-column elements, flex containers, grid containers |
| 继承 | no |
| 百分比 | refer to corresponding dimension of the content area |
| 计算值 | as specified, with <length>s made absolute, and normal computing to zero except on multi-column elements |
| 动画类型 | a length , percentage or calc(); |
normal | <length-percentage>where
<length-percentage> = <length> | <percentage>
<div id="flexbox"> <div></div> <div></div> <div></div> </div>
#flexbox {
display: flex;
height: 100px;
column-gap: 20px;
}
#flexbox > div {
border: 1px solid green;
background-color: lime;
flex: auto;
}
<div id="grid"> <div></div> <div></div> <div></div> </div>
#grid {
grid-column-gap: 20px;
}
#grid {
display: grid;
height: 100px;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: 100px;
column-gap: 20px;
}
#grid > div {
border: 1px solid green;
background-color: lime;
}
<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>
.content-box {
column-count: 3;
column-gap: 40px;
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
CSS Box Alignment Module Level 3
The definition of 'column-gap' in that specification. |
工作草案 | Applies to grid and flexbox |
|
CSS 栅格布局
The definition of 'column-gap' in that specification. |
候选推荐 | Specifies how this property affects grid layouts |
|
CSS Multi-column Layout Module
The definition of 'column-gap' in that specification. |
工作草案 | 初始定义 |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Supported in Flex Layout | Chrome 完整支持 84 | Edge 完整支持 84 | Firefox 完整支持 63 | IE 不支持 No | Opera 完整支持 70 | Safari 不支持 No | WebView Android 完整支持 84 | Chrome Android 完整支持 84 | Firefox Android 完整支持 63 | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 不支持 No |
完整支持
不支持
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Supported in Grid Layout |
Chrome
完整支持
66
|
Edge
完整支持
16
|
Firefox
完整支持
61
|
IE 不支持 No |
Opera
完整支持
53
|
Safari
完整支持
12.1
|
WebView Android
完整支持
66
|
Chrome Android
完整支持
66
|
Firefox Android
完整支持
61
|
Opera Android
完整支持
47
|
Safari iOS
完整支持
12
|
Samsung Internet Android
完整支持
9.0
|
完整支持
不支持
用户必须明确启用此特征。
使用非标名称。
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Supported in Multi-column Layout | Chrome 完整支持 50 | Edge 完整支持 12 |
Firefox
完整支持
52
|
IE 完整支持 10 |
Opera
完整支持
37
|
Safari 完整支持 10 | WebView Android 完整支持 50 | Chrome Android 完整支持 50 |
Firefox Android
完整支持
52
|
Opera Android
完整支持
37
|
Safari iOS 完整支持 10 | Samsung Internet Android 完整支持 5.0 |
calc()
值
|
Chrome 完整支持 66 | Edge 完整支持 16 | Firefox 完整支持 61 | IE 不支持 No | Opera 完整支持 53 | Safari 不支持 No | WebView Android 完整支持 66 | Chrome Android 完整支持 66 | Firefox Android 完整支持 61 | Opera Android 完整支持 47 | Safari iOS 不支持 No | Samsung Internet Android 完整支持 9.0 |
<percentage>
值
|
Chrome 完整支持 66 | Edge 完整支持 16 | Firefox 完整支持 61 | IE 不支持 No | Opera 完整支持 53 | Safari 不支持 No | WebView Android 完整支持 66 | Chrome Android 完整支持 66 | Firefox Android 完整支持 61 | Opera Android 完整支持 47 | Safari iOS 不支持 No | Samsung Internet Android 完整支持 9.0 |
完整支持
不支持
见实现注意事项。
要求使用供应商前缀或不同名称。
row-gap
,
gap
align-content
align-items
align-self
column-gap (grid-column-gap)
gap (grid-gap)
justify-content
justify-items
justify-self
place-content
place-items
place-self
row-gap (grid-row-gap)