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

    Selectors and element states

    Element relationships, hover and focus-visible.

    8 minutes1 games

    .card p selects descendant paragraphs; .card > p selects direct children only. [required] selects by attribute. Pseudo-classes such as :hover and :focus-visible select states; pseudo-elements such as ::before expose a stylable part.

    HTML
    <style>
      .card > p { color: navy; }
      button:hover { background: #bae6fd; }
      button:focus-visible { outline: 3px solid #1d4ed8; outline-offset: 3px; }
      .tag::before { content: "# "; }
    </style>
    <div class="card"><p class="tag">Python</p><button>Start</button></div>
    ToolUse

    A B

    Any matching descendant

    A > B

    Direct child

    :focus-visible

    Focus requiring a visible indicator

    ::before

    Generated part before content

    Important

    Keep essential meaning in HTML, not only in generated content. Hover is not equally available on touchscreens.

    Interview question

    Why include focus-visible alongside hover?

    Exercise

    Color the direct child paragraph green and leave the nested one black.

    HTML
    <style>p {color:black}</style>
    <div class="card"><p>Direct</p><section><p>Nested</p></section></div>

    Learn more from

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

    Played 0 of 1 games

    Sign in to save your progress and earn XP.

    PreviousCascade and specificityNextColours and text
    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.