![]() |
VOOZH | about |
The @container CSS at-rule is a conditional group rule that styles a container context. A condition filters style declarations, which are applied to the container if the condition is true. The condition is evaluated whenever the container size or <style-feature> value changes.
Table of Content
This method involves utilizing CSS's @container rule to set criteria for picking containers based on their characteristics. These properties may comprise attributes such as container name, type, size, position, etc.
@container (min-width > 600px) {
.container {
background-color: lightblue;
}
}
Values refers to the specific criteria or attributes used to define the conditions for container selection. For instance, `container-name` could represent the name assigned to a container element in HTML, while `container-query` could denote a specific query used to identify containers based on certain characteristics.
These keywords are used in container queries to group together numerous conditions. Here's how they are utilized:
/* Example of 'and' keyword */
@media (min-width: 600px) and (max-width: 900px) { ... }
/* Example of 'or' keyword */
@media (max-width: 600px), (min-width: 1200px) { ... }
/* Example of 'not' keyword */
@media not screen and (color) { ... }
The container-name specifies the name of the container element.
/* A single name */container-name: webLayout;/* Global Values */container-name: inherit | initial | revert | revert-layer | unset;
Nested container queries involve placing one container query inside another to create more complex selection logic.
@container (min-width: 600px) {
.container { ... }
@container (min-height: 400px) {
.container { ... }
}
}