Автоматическое количество строк grid css

grid-template-rows

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

The grid-template-rows CSS property defines the line names and track sizing functions of the grid rows.

Try it

Syntax

/* Keyword value */ grid-template-rows: none; /* values */ grid-template-rows: 100px 1fr; grid-template-rows: [linename] 100px; grid-template-rows: [linename1] 100px [linename2 linename3]; grid-template-rows: minmax(100px, 1fr); grid-template-rows: fit-content(40%); grid-template-rows: repeat(3, 200px); grid-template-rows: subgrid; grid-template-rows: masonry; /* values */ grid-template-rows: 200px repeat(auto-fill, 100px) 300px; grid-template-rows: minmax(100px, max-content) repeat(auto-fill, 200px) 20%; grid-template-rows: [linename1] 100px [linename2] repeat(auto-fit, [linename3 linename4] 300px) 100px; grid-template-rows: [linename1 linename2] 100px repeat(auto-fit, [linename1] 300px) [linename3]; /* Global values */ grid-template-rows: inherit; grid-template-rows: initial; grid-template-rows: revert; grid-template-rows: revert-layer; grid-template-rows: unset; 

This property may be specified as:

Values

Is a keyword meaning that there is no explicit grid. Any rows will be implicitly generated and their size will be determined by the grid-auto-rows property.

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, ) ).

Читайте также:  Page Title

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. It is invalid as a 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.

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.

Represents a repeated fragment of the track list, allowing a large number of rows that exhibit a recurring pattern to be written in a more compact form.

The masonry value indicates that this axis should be laid out according to the masonry algorithm.

The subgrid value indicates that the grid will adopt the spanned portion of its parent grid in that axis. Rather than being specified explicitly, the sizes of the grid rows/columns will be taken from the parent grid’s definition.

Warning: The masonry value is from Level 3 of the Grid specification and currently only has an experimental implementation behind a flag in Firefox.

The subgrid value is from Level 2 of the Grid specification and currently only has implementation in Firefox 71 and onwards.

Formal definition

Initial value none
Applies to grid containers
Inherited no
Percentages refer to corresponding dimension of the content area
Computed value as specified, but with relative lengths converted into absolute lengths
Animation type 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

Formal syntax

grid-template-rows =
none |
|
|
subgrid ?

=
[ ? [ | ] ]+ ?

=
[ ? [ | ] ]* ? [ ? [ | ] ]* ?

=
[ | ]+

=
‘[‘ * ‘]’

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

=
repeat( [ ] , [ ? ]+ ? )

=
|
minmax( , ) |
minmax( , )

=
repeat( [ ] , [ ? ]+ ? )

=
repeat( [ auto-fill | auto-fit ] , [ ? ]+ ? )

=
repeat( [ | auto-fill ] , + )

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

=
|
min-content |
max-content |
auto

=
|

=

Examples

Specifying grid row sizes

HTML

div id="grid"> div id="areaA">Adiv> div id="areaB">Bdiv> div> 

CSS

#grid  display: grid; height: 100px; grid-template-rows: 30px 1fr; > #areaA  background-color: lime; > #areaB  background-color: yellow; > 

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.

Источник

grid-auto-rows

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

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

Try it

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

Syntax

/* Keyword values */ grid-auto-rows: min-content; grid-auto-rows: max-content; grid-auto-rows: auto; /* values */ grid-auto-rows: 100px; grid-auto-rows: 20cm; grid-auto-rows: 50vmax; /* values */ grid-auto-rows: 10%; grid-auto-rows: 33.3%; /* values */ grid-auto-rows: 0.5fr; grid-auto-rows: 3fr; /* minmax() values */ grid-auto-rows: minmax(100px, auto); grid-auto-rows: minmax(max-content, 2fr); grid-auto-rows: minmax(20%, 80vmax); /* fit-content() values */ grid-auto-rows: fit-content(400px); grid-auto-rows: fit-content(5cm); grid-auto-rows: fit-content(20%); /* multiple track-size values */ grid-auto-rows: min-content max-content auto; grid-auto-rows: 100px 150px 390px; grid-auto-rows: 10% 33.3%; grid-auto-rows: 0.5fr 3fr 1fr; grid-auto-rows: minmax(100px, auto) minmax(max-content, 2fr) minmax(20%, 80vmax); grid-auto-rows: 100px minmax(100px, auto) 10% 0.5fr fit-content(400px); /* Global values */ grid-auto-rows: inherit; grid-auto-rows: initial; grid-auto-rows: revert; grid-auto-rows: revert-layer; grid-auto-rows: 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-rows =
+

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

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

=
|
min-content |
max-content |
auto

=
|

Examples

Setting grid row size

HTML

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

CSS

#grid  width: 200px; display: grid; grid-template-areas: "a a"; gap: 10px; grid-auto-rows: 100px; > #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.

Источник

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