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

Margin

Inside the card, the name, the age, the description and the button are squeezed together, with no space between them. The space between elements is margin, the space outside the border. Its classes work just like those for padding, only with m instead of p:

ClassCSS
m-4margin: 1rem;
mx-4margin-left: 1rem;
margin-right: 1rem;
my-4margin-top: 1rem;
margin-bottom: 1rem;
mt-4margin-top: 1rem;
mr-4margin-right: 1rem;
mb-4margin-bottom: 1rem;
ml-4margin-left: 1rem;

A habit that keeps things simple: between elements below each other, make the space from one side only, for example always with a top margin (mt-*). Then you never have to think about what happens when two margins meet. (As you saw in the CSS course, the vertical margins of neighboring elements collapse, and the gap is only as big as the larger of them.)

In the card, the name and the age belong together, so they stay close. The description gets more space, and the button the most, so that it stands apart from the text.

Preflight also removed the 8-pixel margin of body, which is why the card touches the edges of the preview. We'll give the page padding: space inside body, between the edge of the window and the content.

Tip: You can see the spaces with Inspect, as in the CSS course: right-click an element in the preview, choose Inspect and hover over the element in the developer tools. The browser shows its padding and margin in different colors.

Instructions

  1. 1

    Add the class mt-4 to the paragraph with the description, so that there are 16 pixels between it and the age.

  2. 2

    Add the class mt-6 to the button.

  3. 3

    Add the class p-8 to body. The card moves 32 pixels away from the edges of the preview.

Back

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