Responsive design
Most people will visit your pages on a phone. Responsive design means one page that adapts to any screen.
1. The viewport tag
Without this line in <head>, phones pretend to be a wide desktop screen and shrink the whole page until it is unreadable:
<meta name="viewport" content="width=device-width, initial-scale=1">
Every page you make should have it.
2. Flexible sizes
Prefer sizes that adapt: percentages, fr in grids, max-width instead of a fixed width:
img {
max-width: 100%; /* never wider than its container */
height: auto;
}
3. Media queries
A media query applies CSS only when a condition is true, usually about the screen width:
.columns {
display: grid;
grid-template-columns: 1fr 1fr;
}
@media (max-width: 600px) {
.columns {
grid-template-columns: 1fr; /* one column on small screens */
}
}
Rules inside the @media block win when the condition matches, because they come later in the file.
Many developers write the phone layout first and use min-width media queries to add columns on bigger screens. Both approaches work; the important thing is to test at phone width (your browser's developer tools have a device toolbar for this).
Your task
- Add the viewport
<meta>tag. - Keep
.cardsat three columns, but add a media query so that on screens up to600pxwide the cards stack in one column.