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

Borders

In this lesson, we'll turn a plain white box into a modern card: with a border, rounded corners, a shadow and a picture that fits in nicely. We'll work on the adoption card of Oscar, a young black cat. The card already has the classes you know from the previous lessons: colors, text sizes, padding and margins, a maximum width, and the class mx-auto, which centers the card.

In the CSS course, you wrote a border with three values: border: 1px solid gray, that is, a width, a style and a color. In Tailwind, each of them has its own classes, and most of the time you need just one: border.

ClassCSS
borderborder-width: 1px;
border-2border-width: 2px;
border-4border-width: 4px;
border-8border-width: 8px;
border-0border-width: 0;

Careful: here, the number is the width in pixels, not a step of the spacing scale. border-2 is 2 pixels, while p-2 is 8.

Why is a width enough? In the CSS course, a border without a style didn't show at all. But Preflight, Tailwind's base styles, gives every element border: 0 solid in advance: a solid line that is 0 pixels wide. As soon as a class gives it a width, the line appears. For other styles, there are the classes border-dashed, border-dotted and border-double.

And the color? Preflight doesn't set one, so a border gets the default color currentColor: the element's text color. That's handy for a button whose border should match its text, but a card with dark text gets a dark frame. Another color comes from the palette you know: border-stone-200 sets border-color to a light shade of stone, just as bg-stone-200 sets the background.

Instructions

  1. 1

    Add the class border to Oscar's card (the div with the id oscar). A thin dark line appears around the card. It has the card's text color, stone-800, which the card inherits from body.

  2. 2

    A dark frame is too heavy for a card. Add the class border-stone-200 too, and the line turns light gray. (A color alone, without border, wouldn't show anything: a border needs a width.)

Back

1/10

  1. 1. Borders
  2. 2. Border on One Side
  3. 3. Rounded Corners
  4. 4. Shadows
  5. 5. Images
  6. 6. Aspect Ratio
  7. 7. Rounded Corners on Pictures
  8. 8. Opacity
  9. 9. A Card from Scratch
  10. 10. Summary
Next

Try it yourself

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