Back to portfolio
INTERACTIVE LEARNING / CSS ENGINEERING

CSS, beyond the basics.

Explore the browser behaviours behind real interface problems, from specificity and stacking contexts to responsive sizing, layouts, and visibility.

14concept notes
3interactive labs
8practice questions
Explore the concepts
01 / CONCEPT LIBRARY

Understand the rules.

Concise explanations and runnable CSS patterns, with modern caveats where older advice can be misleading.

SELECTORS01

Specificity and the cascade

For declarations in the same origin and cascade layer, a more specific selector usually wins.

div { color: red; }
.panel { color: teal; }
#profile { color: gold; }

Type < class/attribute/pseudo-class < ID < inline style in the usual specificity comparison. Importance, origins, cascade layers, and ordering also matter.

SELECTORS02

Children versus descendants

A space matches any descendant; > requires a direct child.

.panel a { text-decoration: underline; }
.panel > a { font-weight: 700; }

Attribute selectors such as [data-status='ready'] and :has() also allow expressive selection in modern browsers.

SELECTORS03

Hover states

A pseudo-class changes a control's appearance when a pointer hovers over it.

.action:hover { background: seagreen; }
.action:focus-visible { outline: 3px solid gold; }

Do not depend on hover alone. Keyboard focus styles and visible labels help interaction remain accessible.

BOX MODEL04

Margin, padding, and borders

The box model flows from margin to border to padding to content.

.box { margin: 0 auto; padding: 16px; border: 2px solid; }

Negative margins are valid. Negative padding, borders, width, and height values are not.

BOX MODEL05

Border-box sizing

With border-box, declared width includes padding and borders.

.box { box-sizing: border-box; width: 280px; padding: 20px; border: 4px solid; }

The default for ordinary elements is content-box. Neither sizing mode includes margins in the declared width.

POSITIONING06

Containing blocks

Absolute positioning is usually relative to the nearest ancestor that establishes its containing block.

.card { position: relative; }
.badge { position: absolute; top: 12px; right: 12px; }

Position: relative retains the element's flow space. Fixed positioning usually uses the viewport, subject to containing-block exceptions.

POSITIONING07

Stacking order

z-index is not limited to values below 1000, and stacking contexts can limit its effect.

.layer { position: relative; z-index: 1000; }

Positioned elements and flex/grid items can use z-index. A large value cannot escape an ancestor stacking context.

LAYOUT08

Floats and clearing

Floats influence text wrapping and can require containment to give the parent height.

.container { display: flow-root; }
.thumbnail { float: left; margin-right: 1rem; }

display: flow-root is a modern containment option. A clearfix with ::after { content: ''; display: block; clear: both; } is another approach.

LAYOUT09

Horizontal and vertical centring

Auto inline margins can centre a width-constrained block; flexbox centres in either axis.

.card { width: 65%; margin: 0 auto; }
.shell { display: flex; align-items: center; justify-content: center; }

With display: table-cell, vertical-align: middle aligns cell content vertically. Aligning table cells differs from styling the table itself.

LAYOUT10

Space-filling flex children

Let the content area grow and prevent an adjacent action from shrinking.

.row { display: flex; gap: 12px; }
.row__content { flex: 1; min-width: 0; }
.row__action { flex: none; }

flex: 1 makes the content expand; flex: none preserves the button's size. This works well for responsive commerce navigation.

RESPONSIVE11

Viewport media queries

max-width applies when the viewport is at or below the specified width.

@media (max-width: 768px) {
  .cards { grid-template-columns: 1fr; }
}

Choose breakpoints around content needs rather than assuming a particular device model.

VISIBILITY12

Hidden versus removed

Three ways of hiding an element have different layout and interaction outcomes.

.invisible { visibility: hidden; }
.removed { display: none; }
.transparent { opacity: 0; }

visibility: hidden keeps space but is not normally pointer-interactive; display: none removes layout space; opacity: 0 keeps space and can still receive pointer input.

RESPONSIVE13

Fonts and fallback

The font shorthand sets several font properties together; @font-face declares download sources.

@font-face {
  font-family: 'Sample';
  src: local('Sample'), url('/sample.woff2') format('woff2');
}

A browser only checks for a named local font when a local() source is specified. WOFF2 is a common webfont format. No font binaries are included in this demo.

LAYOUT14

A footer that stays below content

A flex-column page can keep a short page's footer at the bottom while preserving scrolling.

.page { min-height: 100vh; display: flex; flex-direction: column; }
.main { flex: 1; }

This modern flexbox layout avoids positioning the footer fixed over long content.

02 / EXPERIMENT IN THE BROWSER

Try it, then understand it.

Change the inputs below to see how styles affect dimensions, position within a row, and pointer interaction.

Box sizing inspector

Declared width: 250px ยท border: 4px per side

Content202px

Actual outer width: 250px

Margins are not included in the declared width for either sizing model.

Flexbox row

One growing item and one fixed-size action

Flexible content areaflex: 1; min-width: 0;

Resize the window. The content compresses first, while the button keeps its natural width through flex: none.

Try a hover and keyboard focus state:

Visibility and interaction

Compare different approaches to hiding content

Before
After

Target clicks: 0

Visible controls occupy space and receive input.

03 / ORIGINAL PRACTICE EXERCISES

Check your understanding.

Eight independently written scenarios. No assessment questions or external test materials are reproduced.

0/8 questions answered
01 / SelectorsIn the same cascade layer, which selector has higher specificity?
02 / Box modelA 260px content-box element has 15px padding and a 2px border on each side. What is its outer width without margins?
03 / PositioningWhere does a typical absolutely positioned badge get its containing block?
04 / LayoutHow can a parent establish a block formatting context that contains floated children?
05 / LayoutIn a flex row, which combination makes the text fill remaining width while its button stays its natural size?
06 / VisibilityWhich property makes an element invisible while preserving space and normal pointer hit-testing?
07 / ResponsiveWhich condition includes a viewport width of exactly 768px?
08 / SelectorsWhich selector matches only immediate anchor children of .menu?
Answer every question to see your result.
OPEN, TESTABLE LEARNING EXAMPLE

From CSS understanding to production UI.

The concepts are presented as an independently developed educational project, not as an examination transcript, certification, or a client implementation. All controls work in the browser; no inputs are sent to a backend.

Return to developer portfolio