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

The Cat Cards

The header and the hero are ready. In the editor, you'll find our version; if you copied your own, paste it over ours. Now comes the most important part of the page: the cats.

The section Our Cats (id="cats") has a heading and a div with four cards. Each card is an article with a picture and a div with the name, the age, the description and the button. Oscar's card also has a span with the badge "New". A few reminders from the earlier lessons:

  • Columns for each width. Classes without a prefix apply at every width, sm: from 640 px, md: from 768 px and lg: from 1024 px up. One column for phones, two for tablets and four for computers: grid gap-6 sm:grid-cols-2 lg:grid-cols-4.
  • Cropped pictures. object-cover makes the picture fill its box and cuts off what doesn't fit, so that the cat isn't squashed. The box needs a size: w-full and a ratio (aspect-video, aspect-square) or a fixed height (h-48). A ratio crops the picture the same way at every width.
  • Rounded corners. When a card has rounded corners and the picture reaches its edges, the square corners of the picture stick out. overflow-hidden on the card cuts them off.
  • A badge on the picture. The card gets relative, and the badge absolute and a position such as top-3 left-3, measured from the corner of the card.
  • Buttons at the same height. The descriptions aren't equally long, so the buttons would end up at different heights. Make the card and its div flex columns (flex flex-col), let the div fill the rest of the card (flex-1), and let the description grow too (flex-1): it pushes the button down to the bottom.

Switch the preview to 375, 768 and 1280 px now and then: the grid should have one, two and four columns.

The checks can't move the mouse over a button, so for hover: (and for focus: in the next exercise), they look at the classes in the HTML. If you make your own class for the buttons with @apply, as in the previous lesson, keep the hover: class in the HTML anyway.

Instructions

  1. 1

    Give the section #cats a maximum width in the middle of the page and padding, for example mx-auto max-w-5xl px-4 py-12. Make its heading big and bold: at least 24 px (text-2xl) and at least font-semibold.

  2. 2

    Lay out the cards (the div that holds them) in a grid with gaps: one column on phones, and two to four columns from a breakpoint up, for example grid gap-6 sm:grid-cols-2 lg:grid-cols-4.

  3. 3

    Make each card (article) a box of its own, with rounded corners and a shadow or a border, for example overflow-hidden rounded-2xl bg-white shadow-md. The picture reaches the corners of the card, so the card needs overflow-hidden, or the picture its own rounded corners.

  4. 4

    Crop the pictures: object-cover together with a ratio or a fixed height, for example aspect-video w-full object-cover. And give the text below the picture (the div in each card) padding, for example p-5, so that it doesn't touch the edges of the card.

  5. 5

    Put the "New" badge on Oscar's picture: relative on the card, and on the badge absolute, a position and a background color, for example absolute top-3 left-3 rounded-full bg-emerald-500 px-3 py-1 text-xs font-bold text-white uppercase.

  6. 6

    Style the four Adopt buttons: a background color, padding, rounded corners, the pointer cursor (cursor-pointer) and another color when the mouse is over them (hover:), for example mt-4 cursor-pointer rounded-full bg-brand-500 px-4 py-2 font-semibold text-white hover:bg-brand-600.

Back

2/5

  1. 1. The Header and the Hero
  2. 2. The Cat Cards
  3. 3. Adoption Steps and the Form
  4. 4. Dark Mode and the Footer
  5. 5. Congratulations!
Next

Try it yourself

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