TutreNews Learn

Layout and responsive design

Building a card and debugging with DevTools

Goal: Combine selectors, box model, Flexbox and states in one component and debug it · 11 min

A component brings together everything from this course. Here is a card:

<article class="card">
  <img src="photo.jpg" alt="A mountain lake">
  <div class="card-body">
    <h3>Mountain lake</h3>
    <p>A quiet place to rest.</p>
    <a class="btn" href="#">Read more</a>
  </div>
</article>
.card { border: 1px solid #ddd; border-radius: 8px; overflow: hidden; max-width: 20rem; }
.card img { width: 100%; display: block; }
.card-body { padding: 1rem; display: flex; flex-direction: column; gap: .5rem; }
.btn { align-self: flex-start; padding: .5rem 1rem; background: #0b5fff; color: #fff; border-radius: 4px; text-decoration: none; }
.btn:hover, .btn:focus-visible { background: #0847c4; }

Good practice:

  • Name classes after what something is (card, btn), not how it looks (blue-box).
  • Keep specificity low and flat (one class per rule) so rules are easy to override.
  • Give keyboard users a visible :focus-visible state; never remove outlines without replacing them.
  • Do not signal state by colour alone.

Debugging with the browser's DevTools (right-click → Inspect):

  1. Select the element and read the Styles pane: crossed-out declarations were overridden, and the winning rule is listed.
  2. The Computed tab shows the final value and which rule set it.
  3. The box-model diagram shows content, padding, border and margin sizes.
  4. Edit values live to test ideas; then copy the working CSS into your file.

A typical hunt: "my colour does not apply" → look for a crossed-out line (specificity), a typo (ignored declaration) or a missing semicolon above it.

Worked example: Debugging a colour that does not apply

  1. HTML: <a class="btn">; CSS: nav a { color: black; } and .btn { color: white; }.
  2. DevTools shows ".btn color: white" crossed out. Why? "nav a" is (0,0,2) and ".btn" is (0,1,0): .btn is more specific, so it should win.
  3. If it is crossed out anyway, look for a typo ("colour"), a missing semicolon on the previous line, or another rule such as "#menu a" with an id.
nav a { color: black; }
.btn { color: white; }