Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS Bootstrap 4 Basics (Retired) Responsive Layouts with the Bootstrap Grid Styling Content

I can't get my bottom margin on my h3's to work.

In the video, Guil uses class="m-b-2" with a dash between the "m" and the "b", but in on the updated Bootstrap documentation there is no dash them. It looks like this: class="mb-2". I tried both ways and I still can't get the margin to appear. Maybe there is something else wrong with my code. Would someone mind checking it out?


3 Answers

Rich Donnellan
Rich Donnellan
Treehouse Moderator 27,671 Points

Hey William,

I peeped your code and all looks good. The Bootstrap spacing utility behaves a bit differently now than explained by Guil. Adding the mb-2 class no longer sets the property to 2rem. It now calculates based on a percentage of spacer variables in a sass-map — so value of mb-2 = 1rem * .5rem = 8px (relative to root value of 16px).

$spacer: 1rem !default;
$spacer-x: $spacer !default;
$spacer-y: $spacer !default;
$spacers: (
  0: (
    x: 0,
    y: 0
  1: (
    x: ($spacer-x * .25),
    y: ($spacer-y * .25)
  2: (
    x: ($spacer-x * .5),
    y: ($spacer-y * .5)
  3: (
    x: $spacer-x,
    y: $spacer-y
  4: (
    x: ($spacer-x * 1.5),
    y: ($spacer-y * 1.5)
  5: (
    x: ($spacer-x * 3),
    y: ($spacer-y * 3)

Hope this clears things up a little.

Luke Duffy
Luke Duffy
4,266 Points

How to you write this instead of mb-2?

Luke Duffy Hey what Rich Donnellan is trying to explain is that the syntax for spacing (padding, margin) is a bit different than that of the video... Before you would type property-side-size but now it's property*Side*-size where property and side is no longer separated by "-" so for margin bottom it's "mb-"and the size... Now the other thing that is different is the sizing as Rich mentions the sizing now is calculated

Size of:

  • 0=> Would have a value of 0.
  • 1=> Would multiply 1 Rem * 0.25 = 0.25 Rem
  • 2=> Would multiply 1 Rem * 0.5 = 0.5 Rem
  • 3=> Would multiply 1 Rem * 1 = 1 Rem
  • 4=> Would multiply 1 Rem * 1.5 = 1.5 Rem
  • 5=> Would multiply 1 Rem * 3 = 3 Rem

As you can see we do not have a 2 Rem constant anymore but you can use the 1.5 rem to get the closest design to that of the video.

So, to achieve a margin bottom of 1.5 we would give the element the class of mb-4. Hope this clarifies further!

John Ireland
John Ireland
6,585 Points

Let it also be known that you can throw your own inline styles in there to achieve the same effect. Inline styles aren't best practice, but for the sake of learning this, its been necessary for me. I had to throw in a style="text-align: center" to get the headers to center on the page, as the classes he is providing are not working properly.