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

    Flexbox

    Line items up and spread them in two lines.

    9 minutes3 games

    Put display: flex on the parent and its children line up side by side. Then:

    • justify-content spreads them along the main axis (center, space-between…).
    • align-items aligns them on the cross axis.
    • gap sets the space between them.
    • flex-direction: column stacks them vertically.
    HTML
    <style>
      .nav {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        padding: 12px;
        background: #111827;
      }
      .nav a { color: white; }
      .logo { color: #22d3ee; font-weight: 700; }
    </style>
    
    <div class="nav">
      <span class="logo">SeaCode</span>
      <div><a href="#">Courses</a> · <a href="#">Login</a></div>
    </div>

    Change space-between to center or flex-end and compare.

    .row { flex-direction: row; justify-content: flex-start; align-items: stretch; }

    Change direction and alignment to see how the axes change.

    Important

    The main axis changes with flex-direction. justify-content does not always mean horizontal alignment.

    Interview question

    How can flex items wrap instead of crowding one line?

    Quick question

    You want 3 cards centred horizontally. What do you put on the parent?

    Complete the code

    Stack the items vertically with an 8px gap.

    .list {
      display: ;
      flex-direction: ;
      gap: 8px;
    }

    Exercise

    Make .row a flex container with centred items (justify-content: center).

    HTML
    <style>
      .row {
        
      }
    </style>
    <div class="row"><span>A</span><span>B</span><span>C</span></div>
    

    Learn more from

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

    Played 0 of 3 games

    Sign in to save your progress and earn XP.

    PreviousOverflow and image fittingNextCSS Grid
    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.