row-gap CSS property sets the size of the gap ( gutter ) between an element's grid rows.

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

CSS 栅格布局 initially defined the grid-row-gap property. This prefixed property is being replaced by row-gap . However, in order to support browsers that implemented grid-row-gap and not row-gap for grid, you will need to use the prefixed property as in the interactive example above.

句法

/* <length> values */
row-gap: 20px;
row-gap: 1em;
row-gap: 3vmin;
row-gap: 0.5cm;
/* <percentage> value */
row-gap: 10%;
/* Global values */
row-gap: inherit;
row-gap: initial;
row-gap: unset;
					

<length-percentage>
Is the width of the gutter separating the rows. <percentage> values are relative to the dimension of the element.

形式定义

初始值 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>

范例

Flex layout

这是 实验性技术
检查 浏览器兼容性表格 要小心谨慎在生产中使用这之前。

HTML

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

CSS

#flexbox {
  display: flex;
  flex-wrap: wrap;
  width: 300px;
  row-gap: 20px;
}
#flexbox > div {
  border: 1px solid green;
  background-color: lime;
  flex: 1 1 auto;
  width: 100px;
  height: 50px;
}
					

结果

Grid layout

HTML

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

CSS

#grid {
  grid-row-gap: 20px;
}
					
#grid {
  display: grid;
  height: 200px;
  grid-template-columns: 200px;
  grid-template-rows: repeat(3, 1fr);
  row-gap: 20px;
}
#grid > div {
  border: 1px solid green;
  background-color: lime;
}
					

结果

规范

规范 状态 注释
CSS Box Alignment Module Level 3
The definition of 'row-gap' in that specification.
工作草案 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

Support in Flex layout

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
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

图例

完整支持

完整支持

不支持

不支持

Support in Grid layout

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
Supported in Grid Layout Chrome 完整支持 66
完整支持 66
完整支持 57 Alternate Name
Alternate Name Uses the non-standard name: grid-row-gap
完整支持 29 Alternate Name Disabled
Alternate Name Uses the non-standard name: grid-row-gap
Disabled From version 29: this feature is behind the Enable experimental Web Platform features preference. To change preferences in Chrome, visit chrome://flags.
Edge 完整支持 16
完整支持 16
完整支持 16 Alternate Name
Alternate Name Uses the non-standard name: grid-row-gap
Firefox 完整支持 61
完整支持 61
完整支持 52 Alternate Name
Alternate Name Uses the non-standard name: grid-row-gap
不支持 40 — 59 Alternate Name Disabled
Alternate Name Uses the non-standard name: grid-row-gap
Disabled ). To change preferences in Firefox, visit about:config.
IE 不支持 No Opera 完整支持 53
完整支持 53
完整支持 44 Alternate Name
Alternate Name Uses the non-standard name: grid-row-gap
完整支持 28 Alternate Name Disabled
Alternate Name Uses the non-standard name: grid-row-gap
Disabled From version 28: this feature is behind the Enable experimental Web Platform features preference.
Safari 完整支持 12.1
完整支持 12.1
完整支持 10.1 Alternate Name
Alternate Name Uses the non-standard name: grid-row-gap
WebView Android 完整支持 66
完整支持 66
完整支持 57 Alternate Name
Alternate Name Uses the non-standard name: grid-row-gap
Chrome Android 完整支持 66
完整支持 66
完整支持 57 Alternate Name
Alternate Name Uses the non-standard name: grid-row-gap
完整支持 29 Disabled
Disabled From version 29: this feature is behind the Enable experimental Web Platform features preference. To change preferences in Chrome, visit chrome://flags.
Firefox Android 完整支持 61
完整支持 61
完整支持 52 Alternate Name
Alternate Name Uses the non-standard name: grid-row-gap
不支持 40 — 59 Alternate Name Disabled
Alternate Name Uses the non-standard name: grid-row-gap
Disabled ). To change preferences in Firefox, visit about:config.
Opera Android 完整支持 47
完整支持 47
完整支持 43 Alternate Name
Alternate Name Uses the non-standard name: grid-row-gap
完整支持 28 Alternate Name Disabled
Alternate Name Uses the non-standard name: grid-row-gap
Disabled From version 28: this feature is behind the Enable experimental Web Platform features preference.
Safari iOS 完整支持 12
完整支持 12
完整支持 10.3 Alternate Name
Alternate Name Uses the non-standard name: grid-row-gap
Samsung Internet Android 完整支持 9.0
完整支持 9.0
完整支持 6.0 Alternate Name
Alternate Name Uses the non-standard name: grid-row-gap

图例

完整支持

完整支持

不支持

不支持

用户必须明确启用此特征。

用户必须明确启用此特征。

使用非标名称。

使用非标名称。

另请参阅

元数据

  • 最后修改:
  1. CSS
  2. CSS 参考
  3. CSS Box Alignment
  4. 指南
    1. Box alignment for block, absolutely positioned and table layout
    2. Box alignment in Flexbox
    3. Box alignment in Multi-column Layout
    4. Box alignment in grid layout
  5. 特性
    1. align-content
    2. align-items
    3. align-self
    4. column-gap (grid-column-gap)
    5. gap (grid-gap)
    6. justify-content
    7. justify-items
    8. justify-self
    9. place-content
    10. place-items
    11. place-self
    12. row-gap (grid-row-gap)

Copyright  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1