--- title: row-gap (grid-row-gap) slug: Web/CSS/row-gap translation_of: Web/CSS/row-gap ---
row-gap
该 CSS 属性用来设置行元素之间的间隙({{glossary("gutters","gutter")}}) 大小。
CSS Grid Layout 起初是用 grid-row-gap
属性来定义的,目前逐渐被 row-gap
替代。但是,为了兼容那些不支持 row-gap
属性的浏览器,你需要像上面的例子一样使用带有前缀的属性。
/* <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>
{{csssyntax}}
{{SeeCompatTable}}
<div id="flexbox"> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> </div>
#flexbox { display: flex; flex-wrap: wrap; width: 300px; row-gap: 20px; } #flexbox > div { background-color: lime; flex: 1 1 auto; width: 100px; height: 50px; }
{{EmbedLiveSample('Flex布局', "auto", "120px")}}
<div id="grid"> <div></div> <div></div> <div></div> </div>
#grid { display: grid; height: 200px; grid-template-columns: 200px; grid-template-rows: repeat(3, 1fr); row-gap: 20px; } #grid > div { background-color: lime; }
{{EmbedLiveSample('Grid布局', 'auto', 120)}}
规范 | 状态 | 备注 |
---|---|---|
{{SpecName("CSS3 Box Alignment", "#propdef-row-gap", "row-gap")}} | {{Spec2("CSS3 Box Alignment")}} | 初始定义 |
{{cssinfo}}
{{Compat("css.properties.row-gap.flex_context")}}
{{Compat("css.properties.row-gap.grid_context")}}