Sub topic 3
Adapting Responsive Interfaces from Mobile to Desktop
Assume you know basic HTML, CSS, selectors, the box model, and units such as rem, px, and percentages. A responsive interface changes its structure and sizing as the available space changes. Breakpoints should reflect where the content needs a different arrangement, not a fixed list of devices.
Navigation: from a menu button to links
On a narrow screen, show a menu button and keep navigation hidden until it is opened. On wider screens, show the links in a row. The interaction must remain usable with a keyboard and touch input.
.site-nav ul {
display: none;
}
@media (min-width: 48rem) {
.menu-button {
display: none;
}
.site-nav ul {
display: flex;
gap: 1.5rem;
}
}Do not choose 48rem because it represents a particular tablet. Choose it when the navigation links fit without wrapping or crowding.
Type and spacing
Use fluid values when the change should be gradual. clamp() sets a minimum, preferred fluid value, and maximum:
h1 {
font-size: clamp(1.75rem, 1.25rem + 2vw, 3rem);
}
.page {
padding: clamp(1rem, 3vw, 3rem);
}Keep line length readable even on large frames. A max-width on text often improves scanning.
Responsive images
srcset provides alternative image files. sizes tells the browser how wide the image will appear, so it can select an appropriate file.
<img
src="hero-800.jpg"
srcset="hero-480.jpg 480w, hero-800.jpg 800w, hero-1200.jpg 1200w"
sizes="(min-width: 80rem) 1200px, 100vw"
alt="A team reviewing a layout on three screen sizes">Input differences
Width does not tell you whether a device supports hover. Apply hover-only styling conditionally:
@media (hover: hover) and (pointer: fine) {
.menu-item:hover {
background: #eef;
}
}Touch targets still need sufficient size, visible focus styles, and an action that does not depend on hover.
Container queries
A component can need different layouts depending on its parent rather than the viewport.
.card-list {
container-type: inline-size;
}
@container (min-width: 30rem) {
.card {
display: grid;
grid-template-columns: 8rem 1fr;
gap: 1rem;
}
}This lets the same card work in a sidebar and a wide content column.
Exercise
Exercise
Why should a responsive design be tested between its named breakpoints?
Show answer
Because content can fail at intermediate widths even when it looks correct at the breakpoint values.