Sitemap

CSS Tasks

Task 1: Box Model Geometry & Focus Outline Isolation on an Interactive Card

3 min read4 days ago

--

  • Focus: Box model (width, height, padding, border, margin), outline / outline-offset, and font hierarchy.
  • Objective: Build an interactive reference card component and demonstrate how content-box (default) vs. border-box affects computed dimensions, while ensuring keyboard focus uses a non-layout-shifting outline
  • Requirements:Compare box-sizing: content-box against box-sizing: border-box on .card with explicit width and min-height (avoiding rigid height clipping when text wraps).Define padding, border, and margin cleanly, and style .card-action with a distinct :focus-visible outline and outline-offset so focus indicators remain clear without altering box layout dimensions.Establish clear typographic scale (font-size, font-weight, line-height, letter-spacing) across title, metadata, and body copy.
  • Starter Code:<article class="card" tabindex="0"><span class="card-tag">CSS Box Model</span><h2 class="card-title">Layout Geometry &amp; Focus Rings</h2><p class="card-body">Inspect how padding, borders, and outlines interact with element dimensions.</p><a class="card-action" href="#details">Inspect Spec</a></article>
<article class="card" tabindex="0">
<span class="card-tag">CSS Box Model</span>
<h2 class="card-title">Layout Geometry &amp; Focus Rings</h2>
<p class="card-body">Inspect how padding, borders, and outlines interact with element dimensions.</p>
<a class="card-action" href="#details">Inspect Spec</a>
</article>

Task 2: Vertical Margin Collapse & Flow Spacing in a Technical Changelog

  • Focus: Vertical margin collapsing, padding, border, and editorial typography.
  • Objective: Implement a changelog feed where adjacent vertical margins collapse predictably and explain edge cases where collapsing does not occur (such as when padding or border separates parent and child margins).
  • Requirements:
  1. Style .entry blocks with vertical margin and border accents, using padding to control internal separation between text and borders.
  2. Test how a child heading’s margin-top interacts with its parent container's margin-top when padding-top or border-top is 0 vs. non-zero.
  3. Set readable font-family fallbacks, line-height (1.5–1.7 for prose), and font-weight contrast between headings, timestamps, and descriptions.
  • Starter Code:
<section class="changelog" aria-label="Release Notes">
<article class="entry">
<span class="entry-meta">v1.2.0 • Core Module</span>
<h3 class="entry-title">Updated Box Sizing Defaults</h3>
<p class="entry-desc">Standardized spacing tokens across documentation panels.</p>
</article>
<article class="entry">
<span class="entry-meta">v1.1.0 • Typography</span>
<h3 class="entry-title">Refined Measure and Line Height</h3>
<p class="entry-desc">Improved body legibility on long-form technical notes.</p>
</article>
</section>

Get Ade Code’s stories in your inbox

Join Medium for free to get updates from this writer.

Task 3: Typographic Specimen & Readability Constraints

  • Focus: Text and fonts (font-family, font-size, font-weight, line-height, letter-spacing, text-transform, text-decoration), padding, and border.
  • Objective: Design a typographic style sheet for an academic/technical article excerpt that balances scannability, hierarchy, and visual restraint.
  • Requirements:
  1. Define a cohesive font stack and typographic hierarchy across .eyebrow, .article-heading, .lead-copy, and .body-copy.
  2. Apply text-transform and letter-spacing appropriately on .eyebrow without over-applying uppercase/tracking to body paragraphs.
  3. Style a blockquote or note box using border-left, padding, and distinct font-style / line-height so quoted text stands out clearly from body prose.
  • Starter Code:
<main class="article-wrap">
<p class="eyebrow">Systems &amp; Interfaces</p>
<h1 class="article-heading">Why Predictable Box Geometry Matters</h1>
<p class="lead-copy">Consistent spacing prevents subtle layout shifts during component updates.</p>
<p class="body-copy">When padding, borders, and font metrics are chosen deliberately, components remain legible across screen sizes.</p>
<blockquote class="pull-quote">
Precision in layout spacing reduces visual noise and cognitive load.
</blockquote>
</main>

Task 4: Side-by-Side Box Model Diagnostic Lab

  • Focus: width, height, padding, border, margin, outline, and font rendering side by side.
  • Objective: Build a side-by-side comparison container with two cards using identical base dimensions (width: 240px, height: 140px) to isolate how padding, border, and outline behave in practice.
  • Requirements:
  1. Position .diagnostic-a and .diagnostic-b side by side with a clear horizontal gap (margin or gap).
  2. Give .diagnostic-a box-sizing: content-box and .diagnostic-b box-sizing: border-box with identical width: 240px, height: 140px, padding: 16px, and border: 4px solid ....
  3. Add an outline (with outline-offset) to highlight one state and observe that it paints outside the border edge without increasing the element's box model footprint.
  4. Format headings, labels, and body copy with clear font-size, font-weight, and line-height so content fits cleanly without clipping.
  • Starter Code:
<div class="lab-stage">
<section class="diagnostic-card diagnostic-a">
<h2>Content-Box</h2>
<p>Content width is fixed at 240px before padding and border.</p>
</section>
<section class="diagnostic-card diagnostic-b">
<h2>Border-Box</h2>
<p>Padding and border are included inside the 240px width.</p>
</section>
</div>

This story was drafted on TK.

--

--