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

Width

The card is as wide as the page, so on a big screen, its text runs in very long lines. Width is set by the w-* classes, and their numbers are steps of the same spacing scale: w-64 is 64 steps of 0.25rem, which is 16rem or 256 pixels. Besides numbers, there are classes for widths that depend on the parent or on the window:

ClassCSSWidth
w-12width: 3rem;48 px
w-64width: 16rem;256 px
w-96width: 24rem;384 px
w-1/2width: 50%;half of the parent
w-fullwidth: 100%;the whole parent
w-screenwidth: 100vw;the whole window
w-autowidth: auto;the default

Fractions such as w-1/2, w-1/3, w-2/3 or w-3/4 are a share of the parent's width, like percentages in the CSS course. w-full makes an element as wide as its parent's content, w-screen as wide as the browser window, and w-auto brings back the default width, which the browser works out itself.

A button is an inline-block element, as you know from the CSS course: it's only as wide as its content, but it can be given a width. Buttons as wide as the whole card are common, especially on phones: they're easy to hit with a finger.

Instructions

  1. 1

    Add the class w-96 to the card. It becomes 384 pixels wide. Now click 375 px in the Preview width bar above the preview, which shows the page as wide as a phone's screen: the card doesn't fit and sticks out of the page. We'll fix that in the next exercise. Then switch the preview back with the Fit button.

  2. 2

    Add the class w-full to the button. It becomes as wide as the content of the card.

Back

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