smartyfy.mrindigi.com

Web Development Pro | Lesson 016 | Mobile-First Responsive Design

Web Development Pro · Lesson 16 of 60

Module 2: CSS and responsive design

In this lesson

Prerequisites and learning outcomes

Complete lesson 15 first. This lesson builds on content-driven breakpoints and viewport tests. By the end, you can adapt layouts across small and large viewports without hiding essential content. Plan 10–15 minutes for the core explanation and additional time for the worked practice.

Let content determine the layout

Responsive design means a page adapts to available space and user needs. It does not mean producing one “phone version” and one “desktop version” with nothing useful between them. Browsers can be narrow windows on large monitors, and zoom can reduce the effective space available to a layout. Start with a simple narrow layout that keeps all essential content in a readable order.

The workshop site's introduction, session list, and preparation notes work naturally as stacked blocks. When there is enough room, the session list and notes can sit beside one another. This is an enhancement to the same document. You do not need duplicate copies of the information or a script that guesses the visitor's device model.

Establish a flexible baseline

Use widths that can shrink, images that fit their containers, and text containers that grow vertically. The viewport metadata from earlier lessons helps mobile browsers use an appropriate layout viewport. Avoid disabling zoom with restrictive viewport settings. A design that needs zoom disabled is hiding a usability problem rather than solving it.

* { box-sizing: border-box; }
body { margin: 0; font: 1rem/1.6 system-ui, sans-serif; }
main { width: min(100% - 2rem, 70rem); margin-inline: auto; }
.layout { display: grid; gap: 1.5rem; }
.panel { min-width: 0; padding: 1rem; border: 1px solid #28536b; }
img { max-width: 100%; height: auto; }
@media (min-width: 48rem) {
  .layout { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
}

The base rules produce one column. The min-width query adds a two-column relationship once the viewport is wide enough. Media queries conditionally apply CSS; they do not create a separate document. Existing cascade rules still determine which declarations win. Put the enhancement where its relationship to the base style is easy to follow.

Choose a breakpoint by observing failure

Forty-eight rem is a starting point for this example, not a universal definition of a tablet. Resize the layout and find where two columns can comfortably hold their content. If a long heading becomes cramped before that point, keep the stacked layout longer or adjust the proportions. Let the content's needs justify the breakpoint.

Media-query rem units are based on the initial font size for media-query evaluation, rather than necessarily following a custom root font-size declaration in the same stylesheet. Do not assume changing html font-size rewrites every breakpoint in the way ordinary rem lengths behave. Use browser evidence for the actual layout, especially when supporting user text preferences.

A mobile-first stylesheet often uses min-width queries because the narrow baseline is enhanced as space increases. Max-width queries are also valid when they express a specific requirement clearly. The important practice is to avoid overlapping rules whose combined behavior you cannot explain. A collection of arbitrary breakpoints can become harder to maintain than the original layout.

Preserve information across widths

Do not hide directions or safety instructions just because they make a small screen longer. A visitor on a phone may need that information most urgently. Instead, use concise writing, meaningful headings, and a manageable flow. Optional supporting content may be disclosed carefully, but essential tasks should remain reachable.

Navigation can wrap rather than becoming a custom menu immediately. A collapsible menu requires additional interaction, state, and accessibility work. For three links, a wrapping row is often sufficient. Choose complexity only when the content actually needs it; a fashionable control is not automatically a better interface.

Long tables require a deliberate strategy. A small schedule may fit when cells wrap. A wider data table may need its own horizontal scrolling region with a clear label and keyboard access. Avoid making the entire page horizontally scroll because one table is too wide. Also avoid converting table cells to arbitrary blocks without checking the resulting semantics and associations.

Test a range, including uncomfortable cases

Check a narrow viewport, a wide one, and several widths around each breakpoint. Then enlarge text and browser zoom. Use a long session name and an unbroken string to reveal assumptions. A design that only passes with short placeholder text is not robust enough for real content.

Record the viewport size, zoom, and content used when reporting an issue. “The second card overlaps at a 360 CSS-pixel viewport with enlarged text” is more useful than “mobile is broken.” Browser emulation can help, but actual devices and assistive technologies may still reveal different behavior. State which evidence you have.

This package includes a responsive example and static rule checks. Because browser rendering is unavailable in the authoring environment, no claim is made that its visual behavior was observed. The manual test plan is part of the deliverable, and completing it is necessary before treating the design as visually verified.

Worked practice

Worked exercise 1: Explain the baseline

Task: The viewport is narrower than the min-width query. How many explicit columns does .layout have? Worked answer: no two-column template applies, so the ordinary grid auto-placement produces a single-column flow for these block items. The base content remains available before the enhancement.

Worked exercise 2: Choose a useful breakpoint

Task: Two columns fit at 820px but a long title crowds them at 740px. Worked answer: choose a transition based on that content threshold and retest nearby widths. Do not select a breakpoint only because a device list calls 768px a tablet size.

Worked exercise 3: Repair a hidden instruction

Task: A small-screen rule hides “Bring the item manual.” Worked answer: keep that instruction visible and adjust spacing or layout instead. The information remains relevant at every width. Hiding it saves space by removing task support, which is the wrong tradeoff.

Knowledge check

Question 1

What should a narrow baseline preserve? A) The desktop column count at every width. B) Essential content and tasks. C) Only content that fits without vertical scrolling. D) The exact desktop spacing at every width.

Check question 1: answer and explanation

Answer: B. Responsive adaptation should retain the information users need.

Question 2

What does a media query do? A) Conditionally applies CSS. B) Creates another HTML file. C) Changes the source order automatically. D) Identifies every device model.

Check question 2: answer and explanation

Answer: A. It tests media conditions and participates in the existing stylesheet.

Question 3

Why test around a breakpoint? A) To establish the maximum width a browser supports. B) To replace checks with enlarged text. C) To find awkward transitions and intermediate failures. D) To prove that endpoint screenshots cover all intermediate layouts.

Check question 3: answer and explanation

Answer: C. Boundary widths often expose assumptions that two endpoint screenshots miss.

Question 4

Which is a sound reason to add a collapsed menu? A) The viewport is below a conventional device breakpoint, regardless of content. B) Wrapping links is always less accessible than hiding them. C) A collapsed menu automatically solves keyboard navigation. D) The navigation's actual size and tasks justify the extra interaction.

Check question 4: answer and explanation

Answer: D. Added behavior should solve a demonstrated need.

Question 5

Does viewport metadata alone make a site responsive? A) Yes, it rewrites widths. B) No, the layout must also adapt. C) Yes, it changes all pixels to rem. D) Yes, it wraps all content automatically.

Check question 5: answer and explanation

Answer: B. It sets viewport behavior but does not repair inflexible CSS.

Sources and further reading