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

Padding on One Side

The button still fits tightly around its text: Adopt Luna. Buttons usually need more room on the left and right than at the top and bottom: Adopt Luna. A p-* class sets all four sides the same, so for directions and single sides, Tailwind has more padding classes:

ClassCSS
px-4padding-left: 1rem;
padding-right: 1rem;
py-4padding-top: 1rem;
padding-bottom: 1rem;
pt-4padding-top: 1rem;
pr-4padding-right: 1rem;
pb-4padding-bottom: 1rem;
pl-4padding-left: 1rem;

The letters stand for English words: t for top, r for right, b for bottom and l for left. x and y are the axes you know from math: x is horizontal (left and right) and y vertical (top and bottom). (Tailwind actually writes px-4 as padding-inline: 1rem and py-4 as padding-block: 1rem. In languages written from left to right, these properties are the padding on the left and right, and at the top and bottom.)

Classes can be combined: p-4 pt-8 gives an element 16 pixels on every side except the top, which gets 32. The class for the single side wins whatever the order of the classes, because Tailwind puts the rules for single sides after the rule for all sides in its CSS, and of two equally specific rules, the later one wins, as you know from the cascade. (The order of the classes in the class attribute never matters.) But as you saw in the previous lesson, don't give an element two classes for the same thing, such as p-4 p-6: you can't tell from the HTML which one wins.

Instructions

  1. 1

    Add the classes px-6 and py-3 to the button: 24 pixels on the left and right, and 12 at the top and bottom.

Back

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