gap
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since 2017ë 10ì.
CSS gap ìì±ì íê³¼ ì´ ì¬ì´ì ê°ê²© (gutters)ì ì¤ì í©ëë¤. row-gapê³¼ column-gapì ë¨ì¶ ìì±ì
ëë¤.
ìëí´ ë³´ê¸°
gap: 0;
gap: 10%;
gap: 1em;
gap: 10px 20px;
gap: calc(20px + 10%);
<section class="default-example" id="default-example">
<div class="example-container">
<div class="transition-all" id="example-element">
<div>One</div>
<div>Two</div>
<div>Three</div>
<div>Four</div>
<div>Five</div>
</div>
</div>
</section>
#example-element {
border: 1px solid #c5c5c5;
display: grid;
grid-template-columns: 1fr 1fr;
width: 200px;
}
#example-element > div {
background-color: rgba(0, 0, 255, 0.2);
border: 3px solid blue;
}
grid-gap ì í´ë¹ ìì±ì ë³ì¹ì
ëë¤.
구문
css
/* ë¨ì¼ <length> ê° */
gap: 20px;
gap: 1em;
gap: 3vmin;
gap: 0.5cm;
/* ë¨ì¼ <percentage> ê° */
gap: 16%;
gap: 100%;
/* ì´ì¤ <length> ê° */
gap: 20px 10px;
gap: 1em 0.5em;
gap: 3vmin 2vmax;
gap: 0.5cm 2mm;
/* ì´ì¤ ëë í¼í© <percentage> ê° */
gap: 16% 100%;
gap: 21px 82%;
/* calc() ê° */
gap: calc(10% + 20px);
gap: calc(20px + 10%) calc(10% - 5px);
/* ì ì ê° */
gap: inherit;
gap: initial;
gap: unset;
gap: revert;
gap: revert-layer;
gapì <'row-gap'> ê°ì ì¬ì©í´ ì§ì íë©°, ì íì ì¼ë¡ <'column-gap'>ì ì¶ê°í ì ììµëë¤. <'column-gap'>ì ìëµí ê²½ì° <'row-gap'>ê³¼ ëì¼í ê°ì ì¬ì©í©ëë¤.
<'row-gap'>ê³¼ <'column-gap'>ì ê°ê° <length> ëë <percentage>를 ì¬ì©í´ ì§ì í©ëë¤.
ê°
<length>-
그리ë ì ì ë¶í íë ê°ê²©ì ëë¹.
<percentage>-
그리ë ì ì ë¶í íë ê°ê²©ì ëë¹. ìì í¬ê¸°ì ìëì ì ëë¤.
íì ì ì
| ì´ê¸°ê° | as each of the properties of the shorthand:
|
|---|---|
| ì ì©ëì | multi-column elements, flex containers, grid containers |
| ìì | no |
| ê³ì° ê° | as each of the properties of the shorthand:
|
| Animation type | as each of the properties of the shorthand:
|
íì 구문
gap =
<'row-gap'> <'column-gap'>?
<row-gap> =
normal |
<length-percentage [0,â]> |
<line-width>
<column-gap> =
normal |
<length-percentage [0,â]> |
<line-width>
<length-percentage> =
<length> |
<percentage>
<line-width> =
<length [0,â]> |
hairline |
thin |
medium |
thick
ìì
>íë ì¤ ë ì´ìì
HTML
html
<div id="flexbox">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
CSS
css
#flexbox {
display: flex;
flex-wrap: wrap;
width: 300px;
gap: 20px 5px;
}
#flexbox > div {
border: 1px solid green;
background-color: lime;
flex: 1 1 auto;
width: 100px;
height: 50px;
}
ê²°ê³¼
그리ë ë ì´ìì
HTML
html
<div id="grid">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
CSS
css
#grid {
display: grid;
height: 200px;
grid-template: repeat(3, 1fr) / repeat(3, 1fr);
gap: 20px 5px;
}
#grid > div {
border: 1px solid green;
background-color: lime;
}
ê²°ê³¼
ë¤ì´ ë ì´ìì
HTML
html
<p class="content-box">
This is some multi-column text with a 40px column gap created with the CSS
<code>gap</code> property. Don't you think that's fun and exciting? I sure do!
</p>
CSS
css
.content-box {
column-count: 3;
gap: 40px;
}
ê²°ê³¼
ëª ì¸
| Specification |
|---|
| CSS Gaps Module Level 1 > # gap-shorthand > |
ë¸ë¼ì°ì í¸íì±
ê°ì´ 보기
- ê´ë ¨ CSS ìì±:
row-gap,column-gap - 그리ë ë ì´ìì ìë´ì: Basic concepts of grid layout - Gutters