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 CSS Layout Techniques Display Modes Column Layout with Inline-Block

Manuel Meewezen
Manuel Meewezen
8,627 Points

-5px margin for the 2 divs

I just don't understand why the -5px margin is necessary to place the two divs next to each other. Shouldn't the box-sizing have take care of that? Could someone explain please? Thanks :)

3 Answers

Hi Manuel,

The box-sizing property is what allows you to set the 2 widths on the columns to 60% and 40% and not have to worry about taking into account the 20px of padding each one has.

Since they're inline-block elements you still have to contend with the whitespace issue in the html. The whitespace that exists between the two div's in the html produces a single space between the 2 div's on the rendered page. Much like the gaps between the navigation elements.

A negative 5px margin is then needed to close that gap up.

Manuel Meewezen
Manuel Meewezen
8,627 Points

TY so much for your reply Jason :)

why -5px ? can we use any other

Hi Sunatullo,

The pixel number that you use corresponds to the width of a space. The gap that appears between elements is equal to the width of a single space which is dependent upon the font-family and font-size you have chosen.

So the exact pixel number you use would correspond to whatever the width a 'space' takes up.