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, we learned that:

  • Preflight removes the margins and paddings that browsers give elements, so you add every space yourself.
  • Tailwind's spacing scale has steps of 0.25rem, that is 4 pixels: p-1 is 4 pixels, p-4 16 and p-8 32. Choosing from a few steps keeps the spacing of the whole site consistent.
  • p-* sets the padding on all sides, px-* on the left and right, py-* at the top and bottom, and pt-*, pr-*, pb-* and pl-* on a single side.
  • Margins work the same way with m: m-*, mx-*, my-*, mt-*, mr-*, mb-* and ml-*. Between elements below each other, it's simplest to make space from one side only, for example with mt-*.
  • The order of the classes in class doesn't matter: a class for one side (pt-8) wins over a class for all sides (p-4). Don't give an element two classes for the same thing.
  • w-* and h-* set the width and the height on the same scale (w-64 is 256 pixels). w-full is the width of the parent, fractions such as w-1/2 a share of it, and w-screen and h-screen the size of the window.
  • max-w-sm, max-w-md and the others set a maximum width, so the element shrinks on narrow screens. Together with mx-auto, they make a centered column, like our card.
  • Heights are usually best left to the content. min-h-screen makes an element at least as tall as the window.
  • size-* sets the width and the height at once, and leading-* takes numbers of the scale too.
  • In square brackets, you can write any CSS value, such as bg-[#fdf6ec] or w-[350px] (arbitrary values), without spaces. Use them only as an exception: the scale and the palette keep the site consistent.
  • The Preview width bar shows the page as wide as a phone (375 px) or a computer screen.

Luna's card now has room inside and around it and a sensible width, and it stays in the middle of the page on any screen. Next comes a small project, in which you'll style a whole page on your own, with everything from the first three lessons. Then, in the lesson Borders, Shadows and Images, you'll give cards like this one borders, rounded corners, shadows and a picture.

For practice, we've added a notice with the shelter's address below the card. Give it space and a width with what you've learned in this lesson.

Instructions

  1. 1

    Give the notice padding: 16 pixels on the left and right, and 12 pixels at the top and bottom. Work out the classes from the spacing scale.

  2. 2

    Give the notice the same max width as the card, and center it on the page like the card.

  3. 3

    Make a gap of 24 pixels between the card and the notice: give the notice a top margin.

Back

9/9

  1. 1. The Spacing Scale
  2. 2. Padding on One Side
  3. 3. Margin
  4. 4. Width
  5. 5. Max Width and Centering
  6. 6. Height
  7. 7. Width and Height at Once
  8. 8. Values Outside the Scale
  9. 9. Summary
Next

Try it yourself

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