A small CSS change is easier to understand when you can isolate it from the rest of an application. Here is a short exercise: build one card, make its width predictable, and check what happens when its container gets narrow.

Start with one complete example

Paste this into an HTML preview editor, or save it as card.html and open it in a browser:

<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Card layout experiment</title> <style> * { box-sizing: border-box; } body { margin: 0; padding: 24px; font-family: system-ui, sans-serif; background: #f1f5f9; color: #0f172a; } .card { width: 100%; max-width: 360px; padding: 24px; border: 3px solid #2563eb; border-radius: 16px; background: white; overflow-wrap: anywhere; } h1 { margin-top: 0; font-size: 1.5rem; } a { color: #1d4ed8; } a:focus-visible { outline: 3px solid #0f172a; outline-offset: 4px; } </style> </head> <body> <article class="card"> <h1>A small layout experiment</h1> <p>One card, one change at a time.</p> <a href="#details">Read the details</a> <p id="details">Try a narrower preview, then inspect the card again.</p> </article> </body> </html> 

Change one variable at a time

First, change the border color from #2563eb to #16a34a. The border should turn green without changing the layout. This is a quick check that you are editing the CSS used by the preview.

Next, change max-width: 360px to max-width: 280px. On a sufficiently wide preview, the card becomes narrower. On a preview already narrower than that, you may see little or no difference: width: 100% is still limited by the available container width.

Finally, increase the padding from 24px to 40px. With box-sizing: border-box, padding and borders fit inside the declared width. The content area gets smaller while the card's outer width stays constrained.

Reproduce an overflow bug

Temporarily replace the card's width rules with:

width: 360px; /* Remove max-width for this experiment. */ 

Now make the preview narrower than the card plus the body's horizontal padding. The fixed-width card can overflow. Restore width: 100% and max-width: 360px to let it shrink with its container.

Also try removing the universal box-sizing rule. Under the default content-box model, padding and borders are added outside the declared content width. This helps explain why a supposedly 100%-wide element can become too wide.

Check more than appearance

  • Press Tab and check that the link has a visible focus outline.
  • Add a long, unbroken string and see how overflow-wrap affects it.
  • Check a narrow preview as well as a wide one.
  • Test again in the real page: its existing CSS can change the result.

An isolated preview helps you explore layout behavior; it does not replace browser testing or accessibility checks in your application.

Try the exercise

Disclosure: MwpTools is my website. You can use its HTML Code Editor for this exercise, or run the same snippet locally. No framework or build step is required.

What is the smallest CSS example you use to explain an unexpectedly wide element?