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 7 of 17

    Overflow and image fitting

    overflow, object-fit and robust layouts.

    8 minutes1 games

    When content exceeds its box, overflow controls visibility, clipping or scrolling. overflow:auto scrolls when needed. Use overflow-wrap for long text and object-fit:cover or contain for images in fixed-size boxes, depending on whether cropping is acceptable.

    HTML
    <style>
      .box {max-width:220px;max-height:100px;overflow:auto;overflow-wrap:anywhere;border:1px solid;padding:12px;}
    </style>
    <div class="box">averylongwordwithoutspaceswhichmustnotbreakthelayout<p>More content</p><p>More content</p><p>Last line</p></div>
    .box { overflow: auto; }

    Compare how each setting affects access to content.

    Important

    overflow:hidden may conceal content and focus indicators. Do not use it to hide a layout problem without understanding the cause.

    Interview question

    How do cover and contain differ?

    Exercise

    Limit .box to 100px height and allow scrolling when needed.

    HTML
    <style></style><div class="box"><p>One</p><p>Two</p><p>Three</p><p>Four</p></div>

    Learn more from

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

    Played 0 of 1 games

    Sign in to save your progress and earn XP.

    PreviousUnits and flexible sizingNextFlexbox
    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.