zl程序教程

您现在的位置是:首页 >  前端

当前栏目

[CSS 3] Gap

CSS Gap
2023-09-14 09:00:42 时间

The gap property in CSS is a shorthand for row-gap and column-gap, specifying the size of gutters, which is the space between rows and columns within gridflex, and multi-column layouts.

 

Previously, gap is only available for grid layout, now it is landing for flexbox as well;

 

/* Grid layout */
.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: 1fr 2fr 1fr;
  gap: 30px 20px;
}

/* Flex layout */
.container {
  display: flex;
  gap: 10%;
}

/* Multi-column layout */
.container {
  column-count: 5;
  gap: 20px;
}

 

Syntax:

.container {
  gap: 1rem;
  /* Is equivalent to:
  *  row-gap: 1rem;
  *  column-gap: 1rem
  */
  
  gap: 10px 15%;
  /* Is equivalent to:
  *  row-gap: 10px;
  *  column-gap: 15%;
  */
}

 

More: https://css-tricks.com/almanac/properties/g/gap/