Rendered from responsive/allowed.md

Responsive CSS and Pseudo-elements — Allowed

This gauge covers Chapter 11 after CSS Grid.

Learning goal

Adapt layouts at content-driven breakpoints, keep images usable at changing widths, crop images deliberately, serve resolution- and format-appropriate sources, add decorative generated boxes, and create a native responsive navigation disclosure without moving essential content out of the HTML.

Inherited tools

Everything allowed through ../grid/allowed.md remains available.

Responsive navigation elements

Use them together for a native disclosure menu. The optional open attribute may set its initial state, but responsive navigation should normally begin closed.

Media queries

Responsive images

Pseudo-elements

Pseudo-elements accept inherited presentation and layout properties. A positioned pseudo-element needs the same containing-block reasoning as any other positioned box.

Learning rules

  1. Choose a breakpoint where the content needs a different layout, not from a device-name list.
  2. Keep the base rules usable before adding a media query.
  3. Put media-query overrides after the base declarations they change.
  4. max-width: 100% prevents an image from exceeding its container; height: auto preserves its intrinsic proportions.
  5. Use aspect-ratio when the layout needs a predictable image slot.
  6. object-fit: cover fills that slot and may crop; contain shows the whole image and may leave empty space.
  7. Pair intrinsic width/height with responsive CSS so the browser reserves space before the file loads.
  8. Use srcset/sizes when one image has multiple resolutions; use <picture> when art direction or format (type="image/webp") must change.
  9. Prefer loading="lazy" for below-the-fold images; keep the LCP candidate eager.
  10. ::before and ::after create generated child boxes. Their content property is required for them to appear.
  11. Keep essential words, instructions, status, and controls in HTML. Generated content is presentation, not a reliable replacement for document content.
  12. Use details and summary for a simple no-JavaScript disclosure instead of disguising a checkbox as a menu control.
  13. Prefer a visible Menu label. If the control must show only the hamburger, give summary the accessible name aria-label="Menu" and hide its native marker without changing its disclosure behavior.
  14. At the chosen breakpoint, expose either the desktop links or the disclosure menu so duplicate navigation is not presented simultaneously.
  15. CSS alone does not close the disclosure after navigation or an outside click. Add JavaScript later only if those behaviors become requirements.

Not allowed

Pages

Rules to lean on

Rules 2, 15–19, 33, 39, 54–59, 72–80, 89–98, 99–110, and the performance / image rules added for Core Web Vitals.