Summary
In this lesson, you learned that:
- Tailwind's colors, fonts and other values come from its theme. Each value is a CSS variable, such as
--color-orange-500. You add your own in an@themeblock after@import "tailwindcss";. - A variable whose name starts with
--color-makes a color for all the color classes:--color-brand-500givesbg-brand-500,text-brand-500,border-brand-500,hover:bg-brand-500and others. When you change its value, the color changes everywhere it's used. - A variable whose name starts with
--font-makes a font class:--font-display: "Baloo 2", sans-serif;givesfont-display. Your own--font-sanschanges the font of the whole page. - A web font can be loaded in the stylesheet with
@import url(...). It must come first, before@import "tailwindcss";: the browser skips an@importafter other rules, without an error. - When a list of classes repeats, write the element once, in a template or a component, or edit all the places at once (
Ctrl+D). Otherwise, make your own class: a rule with@applyin@layer components. - Utility classes win over the
componentslayer, so you can adjust your own class with them:btn px-8. - An unknown class in
@applystops the wholestyle.css, and an error appears in red under the preview. @utilitymakes a real utility class, which works with variants, such asmd:bg-stripes. A class from@layer componentsdoesn't.- Arbitrary values are for one-offs. A value that repeats belongs in the theme.
In the next lesson, Final Project, you'll style the whole home page of the shelter on your own, with everything you've learned in this course.
Practice. Oscar is new at the shelter. We've added the label New to his card (a span at the start of the card), and the card now has the class relative, so that the label can be placed on the picture. Make a class of your own for the label, in a second color of the shelter: a green for labels.
Instructions
In @theme, add the color --color-accent-600: #059669; (an accent color is one that draws attention).
In the @layer components block, add a class .badge for small rounded labels with the background bg-accent-600 and white text, for example with @apply rounded-full bg-accent-600 px-3 py-1 text-xs font-bold tracking-wide text-white uppercase;.
Give the label New in Oscar's card the classes badge absolute top-3 left-3. Its position stays in the HTML, like the buttons' margins: it depends on where the label is.
Start programming for free
7/7