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

    Styling foundations · Lesson 2 of 17

    Cascade and specificity

    Understand why one declaration wins.

    8 minutes2 games

    When declarations compete, the cascade resolves them. Origin, importance and layers come before specificity; source order resolves a tie. Within the same context, an id outweighs a class, which outweighs an element selector. Some properties such as color inherit; margin does not inherit by default.

    HTML
    <style>
      p { color: green; }
      .message { color: blue; }
      .message { color: purple; }
    </style>
    <p class="message">Which rule wins?</p>

    Origin, importance and layer

    Specificity

    Source order on a tie

    Important

    Do not use !important as the default fix. Inspect the winning declaration in DevTools and understand the conflict.

    Interview question

    Does the last rule always win?

    Quick question

    What is the final color in the example?

    Exercise

    Use .note to make the paragraph blue despite the red p rule.

    HTML
    <style>p { color: red; }
    /* add a rule */
    </style>
    <p class="note">Note</p>

    Learn more from

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

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousWhat is CSS?NextSelectors and element states
    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.