Flexbox:
CSS Grid:
Grid layout In detail
grid-template-columns: repeat(3, 1fr); grid-template-row: repeat(3, auto); grid-column: 1/3 grid-row: 1/4
Row Overriding
repeat(3, minmax(200px 1fr))
auto-fit & auto-fill
The auto-fill and auto-fit keywords in CSS Grid control how the grid behaves when the grid items don't take up extra space in the grid container.
auto-fill
.container { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
In this example, the grid will create as many 100px columns as it can fit in the container. If there's space left over, it will be distributed equally among the columns.
auto-fit:
.container { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); }
In this example, the grid will create as many 100px columns as it can fit in the container. If there's space left over, it will be distributed equally among the columns, and any empty columns will be collapsed.
subgrid
.container { display: grid; grid-template-columns: 1fr 1fr 1fr; } .item { display: grid; grid-template-columns: subgrid; }
NOTE:-
Container Query
Rules:-
Rules with in effect only the container descendants not the container itself
container size queries are an addition to responsive design not a replacement for media queries.
<article class="card"> <h2>That's No Moon. It's a Space Station.</h2> <p class="text">At 198km diameter, Mimas is bigger than the first Death Star (120km) but smaller than the second (800km). </p> <p class="link"><a href="https://science.nasa.gov/saturn/moons/mimas/" target="_blank" class="button">More about Mimas</a></p> </article> <!-- we can't query cards in container query so only work with descendants--> <!-- Workaround solution would be check below--> <div class="card"> <article > <h2>That's No Moon. It's a Space Station.</h2> <p class="text">At 198km diameter, Mimas is bigger than the first Death Star (120km) but smaller than the second (800km). </p> <p class="link"><a href="https://science.nasa.gov/saturn/moons/mimas/" target="_blank" class="button">More about Mimas</a></p> </article> </div> .card { container-name: card; container-type: inline-size; } @container card (min-width: 200px) { article { background-color: red; } } @container card (min-width: 250px) { article { ... } }
The above is the detailed content of Grid and Flex Layout in CSS. For more information, please follow other related articles on the PHP Chinese website!