Css grid auto columns count

grid

Baseline is determined by this web feature being supported on the current and the previous major versions of major browsers.

The grid CSS property is a shorthand property that sets all of the explicit and implicit grid properties in a single declaration.

Using grid you specify one axis using grid-template-rows or grid-template-columns , you then specify how content should auto-repeat in the other axis using the implicit grid properties: grid-auto-rows , grid-auto-columns , and grid-auto-flow .

Try it

Note: The sub-properties you don’t specify are set to their initial value, as normal for shorthands. Also, the gutter properties are NOT reset by this shorthand.

Constituent properties

This property is a shorthand for the following CSS properties:

Syntax

/* values */ grid: none; grid: "a" 100px "b" 1fr; grid: [linename1] "a" 100px [linename2]; grid: "a" 200px "b" min-content; grid: "a" minmax(100px, max-content) "b" 20%; grid: 100px / 200px; grid: minmax(400px, min-content) / repeat(auto-fill, 50px); /* / [ auto-flow && dense? ] ? values */ grid: 200px / auto-flow; grid: 30% / auto-flow dense; grid: repeat(3, [line1 line2 line3] 200px) / auto-flow 300px; grid: [line1] minmax(20em, max-content) / auto-flow dense 40%; /* [ auto-flow && dense? ] ? / values */ grid: auto-flow / 200px; grid: auto-flow dense / 30%; grid: auto-flow 300px / repeat(3, [line1 line2 line3] 200px); grid: auto-flow dense 40% / [line1] minmax(20em, max-content); /* Global values */ grid: inherit; grid: initial; grid: revert; grid: revert-layer; grid: unset; 

Values

Sets up an auto-flow by setting the row tracks explicitly via the grid-template-rows property (and the grid-template-columns property to none ) and specifying how to auto-repeat the column tracks via grid-auto-columns (and setting grid-auto-rows to auto ). grid-auto-flow is also set to column accordingly, with dense if it’s specified.

Читайте также:  Mod rewrite and php

All other grid sub-properties are reset to their initial values.

Sets up an auto-flow by setting the column tracks explicitly via the grid-template-columns property (and the grid-template-rows property to none ) and specifying how to auto-repeat the row tracks via grid-auto-rows (and setting grid-auto-columns to auto ). grid-auto-flow is also set to row accordingly, with dense if it’s specified.

All other grid sub-properties are reset to their initial values.

Formal definition

  • grid-template-rows : none
  • grid-template-columns : none
  • grid-template-areas : none
  • grid-auto-rows : auto
  • grid-auto-columns : auto
  • grid-auto-flow : row
  • grid-column-gap : 0
  • grid-row-gap : 0
  • column-gap : normal
  • row-gap : normal
  • grid-template-rows : refer to corresponding dimension of the content area
  • grid-template-columns : refer to corresponding dimension of the content area
  • grid-auto-rows : refer to corresponding dimension of the content area
  • grid-auto-columns : refer to corresponding dimension of the content area
  • grid-template-rows : as specified, but with relative lengths converted into absolute lengths
  • grid-template-columns : as specified, but with relative lengths converted into absolute lengths
  • grid-template-areas : as specified
  • grid-auto-rows : the percentage as specified or the absolute length
  • grid-auto-columns : the percentage as specified or the absolute length
  • grid-auto-flow : as specified
  • grid-column-gap : the percentage as specified or the absolute length
  • grid-row-gap : the percentage as specified or the absolute length
  • column-gap : as specified, with s made absolute, and normal computing to zero except on multi-column elements
  • row-gap : as specified, with s made absolute, and normal computing to zero except on multi-column elements
  • grid-template-rows : simple list of length, percentage, or calc, provided the only differences are in the values of the length, percentage, or calc components in the list
  • grid-template-columns : simple list of length, percentage, or calc, provided the only differences are in the values of the length, percentage, or calc components in the list
  • grid-template-areas : discrete
  • grid-auto-rows : by computed value type
  • grid-auto-columns : by computed value type
  • grid-auto-flow : discrete
  • grid-column-gap : a length
  • grid-row-gap : a length
  • column-gap : a length, percentage or calc();
  • row-gap : a length, percentage or calc();

Formal syntax

grid =
|
/ [ auto-flow && dense? ] ? |
[ auto-flow && dense? ] ? /

Источник

grid-auto-columns

Baseline is determined by this web feature being supported on the current and the previous major versions of major browsers.

The grid-auto-columns CSS property specifies the size of an implicitly-created grid column track or pattern of tracks.

Try it

If a grid item is positioned into a column that is not explicitly sized by grid-template-columns , implicit grid tracks are created to hold it. This can happen either by explicitly positioning into a column that is out of range, or by the auto-placement algorithm creating additional columns.

Syntax

/* Keyword values */ grid-auto-columns: min-content; grid-auto-columns: max-content; grid-auto-columns: auto; /* values */ grid-auto-columns: 100px; grid-auto-columns: 20cm; grid-auto-columns: 50vmax; /* values */ grid-auto-columns: 10%; grid-auto-columns: 33.3%; /* values */ grid-auto-columns: 0.5fr; grid-auto-columns: 3fr; /* minmax() values */ grid-auto-columns: minmax(100px, auto); grid-auto-columns: minmax(max-content, 2fr); grid-auto-columns: minmax(20%, 80vmax); /* fit-content() values */ grid-auto-columns: fit-content(400px); grid-auto-columns: fit-content(5cm); grid-auto-columns: fit-content(20%); /* multiple track-size values */ grid-auto-columns: min-content max-content auto; grid-auto-columns: 100px 150px 390px; grid-auto-columns: 10% 33.3%; grid-auto-columns: 0.5fr 3fr 1fr; grid-auto-columns: minmax(100px, auto) minmax(max-content, 2fr) minmax(20%, 80vmax); grid-auto-columns: 100px minmax(100px, auto) 10% 0.5fr fit-content(400px); /* Global values */ grid-auto-columns: inherit; grid-auto-columns: initial; grid-auto-columns: revert; grid-auto-columns: revert-layer; grid-auto-columns: unset; 

Values

Is a non-negative dimension with the unit fr specifying the track’s flex factor. Each -sized track takes a share of the remaining space in proportion to its flex factor.

When appearing outside a minmax() notation, it implies an automatic minimum (i.e. minmax(auto, ) ).

Is a keyword representing the largest maximal content contribution of the grid items occupying the grid track.

Is a keyword representing the largest minimal content contribution of the grid items occupying the grid track.

Is a functional notation that defines a size range greater than or equal to min and less than or equal to max. If max is smaller than min, then max is ignored and the function is treated as min. As a maximum, a value sets the track’s flex factor. As a minimum, it is treated as zero (or minimal content, if the grid container is sized under a minimal content constraint).

Represents the formula min(max-content, max(auto, argument)) , which is calculated similar to auto (i.e. minmax(auto, max-content) ), except that the track size is clamped at argument if it is greater than the auto minimum.

As a maximum represents the largest max-content size of the items in that track.

As a minimum represents the largest minimum size of items in that track (specified by the min-width / min-height of the items). This is often, though not always, the min-content size.

If used outside of minmax() notation, auto represents the range between the minimum and maximum described above. This behaves similarly to minmax(min-content,max-content) in most cases.

Note: auto track sizes (and only auto track sizes) can be stretched by the align-content and justify-content properties. Therefore by default, an auto sized track will take up any remaining space in the grid container.

Formal definition

Initial value auto
Applies to grid containers
Inherited no
Percentages refer to corresponding dimension of the content area
Computed value the percentage as specified or the absolute length
Animation type by computed value type

Formal syntax

grid-auto-columns =
+

=
|
minmax( , ) |
fit-content( )

=
|
|
min-content |
max-content |
auto

=
|
min-content |
max-content |
auto

=
|

Examples

Setting grid column size

HTML

div id="grid"> div id="item1">div> div id="item2">div> div id="item3">div> div> 

CSS

#grid  height: 100px; display: grid; grid-template-areas: "a a"; gap: 10px; grid-auto-columns: 200px; > #grid > div  background-color: lime; > 

Result

Specifications

Browser compatibility

BCD tables only load in the browser

See also

Found a content problem with this page?

This page was last modified on Jul 18, 2023 by MDN contributors.

Your blueprint for a better internet.

MDN

Support

Our communities

Developers

Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.

Источник

Оцените статью