CSS3 & Modern Layouts (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)
CSS Container Queries: `@container` and `container-type: inline-size`.
senior LevelCode ExampleDocker & ContainersSystem Design
In Simple Words:
Media queries @media only evaluate the viewport width of the entire browser window. Container Queries (@container) evaluate the width of the component's direct parent container, allowing reusable components (like cards or widgets) to adapt their layout whether placed in a narrow sidebar or a wide hero banner.
css
/* 1. Define container element */
.card-container {
container-type: inline-size;
container-name: card;
}
/* 2. Responsive styling based on container's width, NOT viewport */
@container card (min-width: 480px) {
.product-card {
display: flex;
flex-direction: row;
gap: 1.5rem;
}
}