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

    Boxes and sizing · Lesson 6 of 17

    Units and flexible sizing

    px, rem, %, min, max and clamp.

    8 minutes1 games

    px is a CSS length unit; rem is relative to the root font size. Percentages depend on the property and containing block. min and max choose sizes; clamp sets a minimum, preferred value and maximum. Combine flexible width with max-width to keep content manageable.

    HTML
    <style>
      .panel { width: min(100%, 32rem); padding: 1rem; box-sizing: border-box; background:#e0f2fe; }
      .panel h2 { font-size: clamp(1.5rem, 4vw, 2.5rem); }
    </style>
    <section class="panel"><h2>Flexible title</h2><p>Resize the preview.</p></section>
    .panel { width: 100%; }

    Observe width relative to the container.

    Important

    100vw can include scrollbar space and cause overflow; width:100% is often more appropriate for an element within a page.

    Interview question

    How do em and rem differ for font-size?

    Exercise

    Give .box width 100%, max-width 300px and border-box sizing.

    HTML
    <style></style><div class="box">Box</div>

    Learn more from

    • MDN: CSS referencedeveloper.mozilla.org
    • web.dev: sizingweb.dev

    Played 0 of 1 games

    Sign in to save your progress and earn XP.

    PreviousPadding, border and marginNextOverflow and image fitting
    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.