Ask Your Question
2

What is the usage of CSS grid's minmax() function with a maximum width restriction of 100%?

asked 2023-05-25 00:38:29 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-05-25 00:39:02 +0000

ladyg gravatar image

The minmax() function in CSS grid is used to define a size range for grid tracks (rows and columns). The first parameter of the function defines the minimum size and the second parameter defines the maximum size.

When the maximum width is set to 100%, it means that the track can grow up to the full width of its container, but not more. This is useful for creating responsive designs where the size of the grid tracks adjusts according to the size of the viewport.

For example, the following code creates a grid with two columns where the first column has a minimum width of 200px and a maximum width of 1fr (to take up all available space), and the second column has a minimum width of 100px and a maximum width of 100% (to prevent it from expanding beyond the width of its container):

.grid {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(100px, 100%);
}
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-25 00:38:29 +0000

Seen: 7 times

Last updated: May 25 '23