grid-column-gap

CSS grid-column-gap Property

The grid-column-gap property sets the size of the gap between the columns.

Length can be specified both by pixels and percentages.

The initially defined grid-column-gap property is replaced by the column-gap property. However, the grid-column-gap prefixed property is used for browser support. Negative values are not allowed.

类目类目
Initial Value0
Applies toMulti-column elements, flex containers, grid containers.
InheritedNo.
AnimatableYes. Gap is animatable.
VersionCSS Grid Layout Module Level 1
DOM Syntaxobject.style.gridColumnGap = “30px”;

Syntax

Syntax

grid-column-gap: normal | length;

Example of the grid-column-gap property:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .grid-container {
        display: grid;
        grid-template-columns: auto auto auto auto;
        grid-column-gap: 30px;
        grid-row-gap: 10px;
        background-color: #666;
        padding: 10px;
      }
      .grid-container > div {
        background-color: #ccc;
        text-align: center;
        padding: 20px 0;
        font-size: 30px;
      }
    </style>
  </head>
  <body>
    <h2>Grid-column-gap property example</h2>
    <div class="grid-container">
      <div>1</div>
      <div>2</div>
      <div>3</div>
      <div>4</div>
      <div>5</div>
      <div>6</div>
      <div>7</div>
      <div>8</div>
      <div>9</div>
      <div>10</div>
      <div>11</div>
      <div>12</div>
    </div>
  </body>
</html>

Result

Example of the grid-column-gap property with the “%” value:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      .grid-container {
        display: grid;
        grid-template-columns: auto auto auto auto;
        grid-column-gap: 20%;
        grid-row-gap: 10px;
        background-color: #666;
        padding: 10px;
      }
      .grid-container > div {
        background-color: #ccc;
        text-align: center;
        padding: 20px 0;
        font-size: 30px;
      }
    </style>
  </head>
  <body>
    <h2>Grid-column-gap property example</h2>
    <div class="grid-container">
      <div>1</div>
      <div>2</div>
      <div>3</div>
      <div>4</div>
      <div>5</div>
      <div>6</div>
      <div>7</div>
      <div>8</div>
    </div>
  </body>
</html>

Values

Values

ValueDescriptionPlay it
noneThis is the default value of this property, which is equal to 0.Play it »
lengthThe gap between columns is specified by px or percentages. Negative values are not allowed.Play it »
initialMakes the property use its default value.
inheritInherits the property from its parents element.


请遵守《互联网环境法规》文明发言,欢迎讨论问题
扫码反馈

扫一扫,反馈当前页面

咨询反馈
扫码关注
返回顶部