The Range Syntax Has Come to Container Style Queries and if()
attr() function. attr() function. The CSS @container at-rule lets us apply styles to other elements depending on a container’s size or styles. It works almost the same way as a traditional @media query but we are not limited to only querying the viewport.
.parent … Modern CSS keeps giving us a lot of new, easier ways to solve old problems, but often the new features we’re getting don’t only solve old problems, they open up new possibilities as well.
Container queries are one of those …
The CSS container property is a shorthand that combines the container-name and container-type properties into a single declaration.
.parent {
container: cards-grid / inline-size;
/* Equivalent to: */
container-name: cards-grid;
container-type: inline-size;
}
Constituent properties
The container property is a …
The CSS container-type property is part of the Container Queries feature used to register an element as a container that can apply styles to other elements when it meets certain conditions.
.parent {
container-type: inline-size;
}
@container (width < 500px) … The CSS container-name property is used to register an element as a container that applies styles to other elements based on the container’s size and styles.
.parent {
container-name: cards;
container-type: inline-size;
}
@container cards (width 800px) {
.child {
…