The situation
You are the front-end developer at Northdesk, a small company that sells desks, lamps and bags online. The storefront was built by an agency that only ever looked at it on a laptop.
Most visitors now arrive on their phones, and most of them leave within seconds. On a phone the page is wider than the screen, so people have to scroll sideways, the menu runs off the edge, the heading takes up the whole screen, and the products are squeezed into three tiny columns.
From the marketing lead: "On my phone I have to pinch and scroll sideways to see anything. Our competitors' sites just work. Can we fix this before the spring campaign?"
Your tasks
Task 1: Let phones use their real width
public/index.html is missing the viewport meta tag. Without it, phones pretend the screen is about 980px wide and shrink the whole page. Add it inside <head>:
<meta name="viewport" content="width=device-width, initial-scale=1" />
Task 2: Make the layout fit every screen
The page is styled with Tailwind CSS: the styles are classes in the components (src/App.js, src/components/Header.js, src/components/ProductCard.js). Change the classes. src/App.css holds one custom rule, and you can add plain CSS there if you need it; the tests read it too.
Tailwind is mobile-first. A class with no prefix applies at every width, and a prefixed class applies from that width up: sm: from 640px, md: from 768px, lg: from 1024px, xl: from 1280px. max-md: and similar apply below a width. So write the phone layout without a prefix, then add md: and lg: classes for bigger screens. Arbitrary values such as w-[480px] or max-w-[1100px] work too.
Phone (375px):
- Nothing has a fixed width wider than the screen. Prefer
max-w-* (with w-full) to a fixed w-* for the page, or only apply fixed widths from a larger breakpoint. - The header has no fixed height, and the menu links wrap onto a new line (or stack, or sit behind a menu button) instead of running off the edge.
- The hero shows the text above the picture.
- The main heading is 36px (
text-4xl) or smaller, or scales with the screen. - Products are in one column, and so is the footer.
Tablet (768px): products are in two columns.
Desktop (1200px): keep it as it is now: products and footer in three columns, with the hero text beside the picture.
Keep the product list and the footer as grids, and keep the data-section attributes: the tests use them to find each part of the page. You can add elements and classes.
Task 3: Check it by eye
Use the Phone, Tablet and Desktop buttons above the preview to see each size. You can also open the preview in a new tab and resize the window, or use your browser's device mode. You should never need to scroll sideways, and the buttons should be easy to tap.
How the tests work
The tests can't see the preview, and Tailwind doesn't run inside them. Instead they read the Tailwind classes on each element and work out which apply at 375px (phone), 768px (tablet) and 1200px (desktop), using Tailwind's breakpoints and default sizes. So they check the classes you wrote, not pixels on a screen. Always check the preview by eye too.
They understand Tailwind's layout classes: flex, grid, hidden, block, flex-col / flex-row, flex-wrap, grid-cols-*, w-*, min-w-*, max-w-*, h-*, size-*, p-* / px-*, gap-*, text-<size> and overflow-x-*, with any breakpoint prefix and arbitrary values. Colours, borders and other classes don't affect the tests.
Project files
package.json
public/
index.html
src/
index.js
index.css
App.js
App.css
components/
Header.js
ProductCard.js
data/
products.js
responsive.test.js
test-utils/
layout.jssrc/App.js: the storefront page and its Tailwind classes: the page wrapper, hero, best-sellers grid and footer. Most of your work is here.src/App.css: one custom rule (the hero picture's gradient). You can add your own CSS here too; the tests read it.src/components/Header.js: the logo, the menu (data-section="nav") and the cart link.src/components/ProductCard.js: one product card: a colour block, the name, the price and an Add to cart button.src/data/products.js: the six products shown in the grid.public/index.html: the HTML page the app is loaded into (the page background classes are on <body>). Task 1 is here.src/responsive.test.js: the tests, grouped by screen size.src/test-utils/layout.js: a helper the tests use to work out which Tailwind classes (and any CSS) apply at a given screen width. You don't need to change it.package.json, src/index.js and src/index.css: the standard React app setup. src/index.js starts the app and loads Tailwind CSS. You don't need to change these.
How to check your work
- Tests: press ▶ Run tests next to the Tests heading in the bottom panel. They don't re-run on their own, so run them again after each change. PASS means every visible test passed.
- Preview: the bottom-left panel shows the running app and rebuilds as you type. Use Open in new tab above it, or Copy link and paste it into a new tab, to see it full size. That tab follows your edits.
- Your work is saved in this browser. Reset (top right) puts the starting code back.