فهرست فصل‌ها دانلود آرشیوناشر

MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونه‌کد

The CSS gaps module lets you specify spacing, or "gaps", between items in multi-column, flexbox, and grid layouts. The CSS multi-column layout module originally defined gaps and rules that control the spacing between columns in multi-column containers. This module expands on these visible separators, called _gap decorations_, extending it to grid and flexbox.

While {{cssxref("margin")}} and {{cssxref("padding")}} specify visual spacing around individual boxes, the properties in this module enable specifying the spacing between adjacent boxes within a given layout context for layouts that have {{glossary("gutters")}} and gaps, when the spacing is different between sibling boxes as opposed to between the first box, last box, and the container's edge. You can show rules in every gap or in a subset of gaps, defining fully animatable rule widths, colors, and insets.

Gap decorations are painted within a gap as one or more gap decoration segments, with segments occurring between any two adjacent items. When all segments are drawn, column and row rules span the entire height and width of the container. The {{cssxref("rule-visibility-items")}} property defines whether segments are to be drawn around areas that are not occupied by items. The {{cssxref("rule-break")}} properties determine if lines break when they intersect a gap, while {{cssxref("rule-inset")}} defines where segments start and end when rules do break. If they don't break, the {{cssxref("rule-overlap")}} property defines the painting order of the rules.

Gaps in action

In this example, the 2021 poem from the USA inauguration, _The Hill We Climb_, by Amanda Gorman, is displayed across multiple columns, similar to the way articles are displayed in printed newspapers. If you have JavaScript enabled, controls enable changing the {{cssxref("column-gap")}}, {{cssxref("column-rule-color")}}, {{cssxref("column-rule-style")}} and {{cssxref("column-rule-width")}} properties, as well as the preferred number of columns and whether the title and a quote should span all of the columns.

html hidden live-sample___multicol
js hidden live-sample___multicol
css hidden live-sample___multicol

{{EmbedLiveSample("multicol", "", "800px")}}

When the column rule is larger than the column gap, the decorative line appears behind the text; it doesn't change the size of the gap.

Reference

Properties

  • {{cssxref("column-gap")}}
  • {{cssxref("column-rule")}}
  • {{cssxref("column-rule-break")}}
  • {{cssxref("column-rule-color")}}
  • {{cssxref("column-rule-inset")}}
  • {{cssxref("column-rule-inset-cap")}}
  • {{cssxref("column-rule-inset-cap-end")}}
  • {{cssxref("column-rule-inset-cap-start")}}
  • {{cssxref("column-rule-inset-end")}}
  • {{cssxref("column-rule-inset-junction")}}
  • {{cssxref("column-rule-inset-junction-end")}}
  • {{cssxref("column-rule-inset-junction-start")}}
  • {{cssxref("column-rule-inset-start")}}
  • {{cssxref("column-rule-style")}}
  • {{cssxref("column-rule-visibility-items")}}
  • {{cssxref("column-rule-width")}}
  • {{cssxref("gap")}}
  • {{cssxref("row-gap")}}
  • {{cssxref("row-rule")}}
  • {{cssxref("row-rule-break")}}
  • {{cssxref("row-rule-color")}}
  • {{cssxref("row-rule-inset")}}
  • {{cssxref("row-rule-inset-cap")}}
  • {{cssxref("row-rule-inset-cap-end")}}
  • {{cssxref("row-rule-inset-cap-start")}}
  • {{cssxref("row-rule-inset-end")}}
  • {{cssxref("row-rule-inset-junction")}}
  • {{cssxref("row-rule-inset-junction-end")}}
  • {{cssxref("row-rule-inset-junction-start")}}
  • {{cssxref("row-rule-inset-start")}}
  • {{cssxref("row-rule-style")}}
  • {{cssxref("row-rule-visibility-items")}}
  • {{cssxref("row-rule-width")}}
  • {{cssxref("rule")}}
  • {{cssxref("rule-break")}}
  • {{cssxref("rule-color")}}
  • {{cssxref("rule-inset")}}
  • {{cssxref("rule-inset-cap")}}
  • {{cssxref("rule-inset-end")}}
  • {{cssxref("rule-inset-junction")}}
  • {{cssxref("rule-inset-start")}}
  • {{cssxref("rule-overlap")}}
  • {{cssxref("rule-style")}}
  • {{cssxref("rule-visibility-items")}}
  • {{cssxref("rule-width")}}

Terms and glossary definitions

  • {{glossary("Grid")}}
  • {{glossary("Grid cell")}}
  • {{glossary("Grid column")}}
  • {{glossary("Grid lines")}}
  • {{glossary("Grid row")}}
  • {{glossary("Gutters")}}

Guides

Related concepts

CSS flexible box layout module

  • {{cssxref("flex")}}
  • {{cssxref("flex-basis")}}
  • {{cssxref("flex-direction")}}
  • {{cssxref("flex-flow")}}
  • {{cssxref("flex-grow")}}
  • {{cssxref("flex-shrink")}}
  • {{cssxref("flex-wrap")}}

CSS grid layout module

  • {{CSSxRef("grid")}}
  • {{CSSxRef("grid-column")}}
  • {{CSSxRef("grid-row")}}
  • {{cssxref("repeat()")}}

CSS multi-column layout module

  • {{cssxref("column-fill")}}
  • {{cssxref("column-span")}}
  • {{cssxref("columns")}} shorthand
  • {{cssxref("column-count")}}
  • {{cssxref("column-height")}}
  • {{cssxref("column-width")}}
  • {{cssxref("column-wrap")}}
  • {{cssxref("::column")}}

CSS box alignment

  • {{cssxref("align-content")}}
  • {{cssxref("justify-content")}}

CSS box sizing module

  • {{cssxref("height")}}
  • {{cssxref("max-height")}}
  • {{cssxref("block-size")}}
  • {{cssxref("width")}}
  • {{cssxref("max-width")}}

CSS display module

Specifications

{{Specifications}}

See also