Regla @container de CSS
Definition and usage
CSS @container
Rules are used to define styles for other elements based on the container's size or style.
Style declarations are filtered based on conditions. If the condition is true, they are applied to the container. The condition is re-evaluated when the container's size or style value changes.
Tip:In CSS, a container is an element that wraps other elements, used to group them for styling purposes.
Example
Define styles for other elements based on the size or style of the container:
.parent { container-name: myContainer; container-type: inline-size; } /* Add styles if myContainer is less than 500px wide */ @container myContainer (width < 500px) { .child { width: 50%; border: 2px solid maroon; background-color: salmon; } }
CSS syntax
@container containername (containerquery) { css declarations }
Attribute value
Value | Description |
---|---|
containername | Optional. The name of the container. |
containerquery |
Required. The condition to evaluate. If the condition is true, apply the style. can be containerquery The following descriptors are used in
|
Browser support
The numbers in the table represent the first browser version to fully support the @ rule.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
105 | 105 | 110 | 16 | 91 |