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

Opacity

Under Oscar's card, we've added a smaller one for Bella, a cat who has already found a new home. Visitors like to see happy endings like this, but the card shouldn't draw attention away from the cats who are still waiting. A common way to say "this one is done" is to fade the card out.

In the CSS course, you learned about the opacity property, and in Tailwind, it's the opacity-* classes. The number is a percentage: opacity-60 is opacity: 60%, the same as 0.6. opacity-0 makes an element invisible (it still takes up its space, though), and opacity-100 is fully visible, the default. Any number from 0 to 100 works, such as opacity-25 or opacity-80.

Remember the difference from a color with a slash, such as bg-orange-500/50, from the lesson on colors and text: the slash makes only that one color see-through. opacity fades the whole element with everything in it: its text, background, border, pictures and the elements inside it.

bg-orange-500/50

bg-orange-500 opacity-50

Because the elements inside fade along with their parent, a child can't be less transparent than its parent: opacity-100 on the heading of a faded card doesn't bring it back. If something inside should stay clear, fade only the other parts.

Instructions

  1. 1

    Add the class opacity-60 to Bella's card (the div with the id bella). The whole card fades: the texts, the badge and the border.

Back

8/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.