Nesting
CSS Nesting
Native CSS feature allowing selectors to be nested inside parent rules using the & symbol, reducing repetition.
รายละเอียดทางเทคนิค
CSS Nestings require a containment context declared with container-type: inline-size on the parent element. The @container rule then queries the container's dimensions rather than the viewport. Container query units (cqw, cqh, cqi, cqb) resolve relative to the query container. This enables truly reusable components that adapt to their available space regardless of viewport size — solving the long-standing limitation of media queries in component-based architectures.
ตัวอย่าง
```css
/* Example: Nesting */
.element {
/* Apply nesting to this element */
display: block;
margin: 0 auto;
}
```