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

    Positioning and stacking

    relative, absolute, fixed and sticky.

    8 minutes1 games

    relative keeps the element in flow and allows offsets. absolute removes it from flow and commonly positions it against the nearest positioned ancestor. fixed is usually viewport-relative; sticky stays in flow and sticks at an inset such as top:0 within its scrolling context.

    HTML
    <style>
      .card {position:relative; padding:40px 16px 16px; background:#fef3c7;}
      .badge {position:absolute; top:8px; right:8px; background:#92400e; color:white; padding:4px;}
    </style>
    <article class="card"><span class="badge">New</span><h2>Python</h2><p>Learn at your pace.</p></article>
    ToolUse

    relative

    Keeps flow space

    absolute

    Out of flow

    sticky

    Sticks at a scroll threshold

    Important

    A large z-index cannot escape its stacking context. Properties such as transform can create a new context.

    Interview question

    Why might an absolute badge move to the page corner?

    Exercise

    Position .badge at the top right of .card with 8px insets.

    HTML
    <style></style><div class="card"><span class="badge">New</span>Card</div>

    Learn more from

    • MDN: CSS referencedeveloper.mozilla.org
    • web.dev: z-indexweb.dev

    Played 0 of 1 games

    Sign in to save your progress and earn XP.

    PreviousCSS GridNextResponsive design
    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.