CodeCamp ✦

Practical webmaster skills

Your web page works. Now make it hold together.

A card slips off the phone screen, or an image disappears after upload. Find the cause before adding another CSS rule.

Bring a page you can already edit. The examples below work through image paths, heading structure and an overflowing card row.

HTML gives the page meaning. CSS decides how it fits.

The browser’s developer tools let you inspect those rules while the page is running.

The HTML container used by the CSS example

The grid rule below expects a container with class="cards". This small HTML example supplies that container and its children.

<div class="cards">
  <article><h2>First card</h2><p>Card text.</p></article>
  <article><h2>Second card</h2><p>Card text.</p></article>
  <article><h2>Third card</h2><p>Card text.</p></article>
</div>

Three familiar bugs, with somewhere useful to start.

Diagnose the symptom before adding another rule.

The image has vanished

An image path is an address, not the place where you happened to save the file. A relative path starts from the HTML document’s folder.

Letter case also matters on many web servers.

For example: If about/index.html uses images/team.jpg, it asks for about/images/team.jpg. Use ../images/team.jpg to reach an images folder beside about.

The whole card row runs off-screen

A fixed width can make a layout wider than its container. Inspect the overflowing element, then look for width rules, large minimum sizes or a long unbroken URL before hiding the overflow.

For example: Three cards set to 300px each need at least 900px before gaps. Giving the page overflow:hidden only conceals the problem.

The heading looks right but means the wrong thing

Heading elements describe the document’s hierarchy; their size can be changed with CSS. Turning ordinary text into a huge bold paragraph does not make it a heading.

For example: Use an h2 for a section such as “Workshop dates”, then h3 for its individual sessions. Choose the text size separately.

Put the idea to work

Find the rule that broke the layout

When a page overflows, use the browser’s Inspect command on the problem area. Developer tools show the selected element and the CSS affecting it.

Temporary edits are a fast experiment; they are not saved back to your source file.

Work from the failing element back to its container; a neat wireframe alone cannot reveal a width bug.
  1. Reproduce the failure. Narrow the window until the card row first stops fitting. That width is more informative than “it looks wrong on mobile”.Try this: Test a long product name as well as the short title you used while designing.
  2. Toggle a suspect declaration. In developer tools, disable one width or minimum-width rule and watch what changes. If nothing changes, check the parent container rather than adding competing overrides.Try this: Disable width:300px on a card. If the row now fits, replace the rigid sizing in the source.
  3. Retest real content. A layout fix needs to survive text growth, not just your sample screenshot. Browser edits disappear on reload unless you copy the change into your CSS file.Try this: Save the fix, reload, enlarge the text and tab through the links to confirm the content remains reachable.

Practical webmaster skills

Let the card row decide how many columns fit.

This CSS is a starting point for a container whose class is cards. Grid arranges the children; auto-fit uses as many columns as fit.

Each column aims to be at least 16rem wide, but min(100%, 16rem) lets it shrink inside a narrower container. The remaining space is shared using 1fr.

CSS · apply to the card container

.cards {
  display: grid;
  grid-template-columns:
    repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
  gap: 1rem;
}
Less useful

Three fixed-width cards, with the third clipped on a narrow screen.

More specific

One column when space is tight; more columns when the container has room.

Keep the HTML reading order sensible. Grid changes the arrangement; it does not repair confusing content or an image with an incorrect address.

Guides from other websites

Further reading

Follow an external guide, then try one thing.

External guide · developer.mozilla.org

MDN: CSS grid layout ↗

Work through grid tracks and flexible columns with executable CSS examples. Compare the rules with the container you are debugging.

Put it into practice: Compare MDN’s grid examples with your own card container, then test a long heading at a narrow width.

Debug one overflowing card row

Use a copy of your page so you can compare the change with the original.

  1. Give one card a deliberately long title and narrow the browser window.
  2. Inspect the first element that extends beyond its container.
  3. Try the grid rule above, saving the change in your CSS file.
  4. Reload and check a single-column view, longer text and keyboard navigation.