Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    { }CSS

    Styling foundations

    • What is CSS?
    • Cascade and specificity
    • Selectors and element states
    • Colours and text

    Boxes and sizing

    • Padding, border and margin
    • Units and flexible sizing
    • Overflow and image fitting

    Layout and responsiveness

    • Flexbox
    • CSS Grid
    • Positioning and stacking
    • Responsive design
    • Container-based responsiveness

    Design values, direction and motion

    • CSS custom properties and functions
    • Logical properties for RTL and LTR
    • CSS transitions and transforms
    • Keyframes and bounded animation
    • Project: a product card
    CSS

    Layout and responsiveness · Lesson 12 of 17

    Container-based responsiveness

    A card adapting to its available space.

    8 minutes1 games

    A media query observes the viewport; a container query observes a container. Set container-type:inline-size on an ancestor and use @container to adapt descendants to its width. Start with a usable base layout that works without the query.

    HTML
    <style>
      .wrapper {container-type:inline-size;resize:horizontal;overflow:auto;width:300px;max-width:100%;border:1px solid;padding:8px;}
      .card {display:grid;gap:12px;}
      .card > div {background:#e0f2fe;padding:16px;}
      @container (min-width:400px) {.card {grid-template-columns:1fr 2fr;}}
    </style>
    <div class="wrapper"><div class="card"><div>Image</div><div>Resize the wrapper from its corner.</div></div></div>
    ToolUse

    @media

    Viewport size

    @container

    Ancestor container size

    Important

    A size query generally styles descendants, not the query container itself based on its own size.

    Interview question

    Why might one component need two layouts on the same screen?

    Exercise

    Make .wrapper an inline-size query container and .card a grid.

    HTML
    <style></style><div class="wrapper"><div class="card">Card</div></div>

    Learn more from

    • MDN: CSS referencedeveloper.mozilla.org
    • web.dev: container-queriesweb.dev

    Played 0 of 1 games

    Sign in to save your progress and earn XP.

    PreviousResponsive designNextCSS custom properties and functions
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.