Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

Summary

In this lesson, you made the shelter's home page responsive, and you learned that:

  • A responsive page adapts its layout to the width of the screen. In the bar above the preview, you can see a page as wide as a phone (375 px), a tablet (768 px) or a computer (1280 px).
  • Every responsive page needs <meta name="viewport" content="width=device-width, initial-scale=1"> in head. Without it, phones lay the page out as if their screen were about 980 px wide.
  • In CSS, styles meant only for some widths are written in a media query: @media (width >= 48rem) { ... }. In Tailwind, you put a prefix in front of a class instead: md:text-6xl.
  • A class without a prefix applies at every width, a class with a prefix from its breakpoint up: sm: from 640 px, md: from 768 px, lg: from 1024 px, xl: from 1280 px and 2xl: from 1536 px.
  • Mobile first: style the page for a phone with classes without prefixes, then add classes with prefixes for what changes on wider screens.
  • One element can have classes for several breakpoints, such as grid-cols-1 sm:grid-cols-2 lg:grid-cols-4. When several of them apply, the one for the widest screen wins.
  • flex-col md:flex-row puts elements one under another on a phone and side by side from 768 px up.
  • hidden md:flex shows an element only from 768 px up, and md:hidden only below 768 px.
  • Spacing and text sizes can change with the width too: py-12 md:py-24, text-4xl md:text-6xl.
  • mx-auto max-w-5xl on the element with the content keeps it from spreading across a wide screen, while the section's background still fills the whole width.

Next comes one more small project: a website for a cat café, with states and a layout for every screen. Then, in the lesson Dark Mode, you'll give the shelter's website dark colors for everyone who prefers them, and a button that switches between the light and the dark look.

To practice, here's a new piece of the website: a bigger footer with the shelter's name, address and a Donate button. Like the home page at the start of this lesson, it's laid out for a computer only: on a phone, its three columns are squeezed side by side.

Instructions

  1. 1

    Lay out the footer's columns mobile first: add the classes flex-col and md:flex-row to the div with the three columns. On a phone, the columns are one under another, and from 768 px up, side by side.

  2. 2

    One under another, the columns look better centered: add the classes text-center and md:text-left to the same div. Look at the footer at 375 px and at 768 px.

Back

7/7

  1. 1. Mobile First
  2. 2. Breakpoints
  3. 3. Row or Column
  4. 4. Hiding and Showing
  5. 5. Spacing for Each Width
  6. 6. Content Width on Big Screens
  7. 7. Summary
Next

Try it yourself

Do this exercise right here in your browser. No account needed.