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

Negative Margin vs Float.

Hallo,

First off, I used the following CSS for this challenge:

.col {
    display: inline-block;
    vertical-align: top;
    width: 50%;
    float: left;
    padding-left: 1em;
    padding-right: 1em;
}

I did some research online on the various fixes/workarounds for the inline-block whitespace 'bug' and floating the columns seemed to be the least 'hacky' option. Is there there a situation where a negative margin is better than a float here?

Hopefully they'll teach us flexbox soon. ;-)

Thank you!

-Joshua

1 Answer

Steven Parker
Steven Parker
242,296 Points

A negative margin won't usually work as a substitute for a float.

Most often when you use float your as or more interested in having elements nest together or having text wrap around them as you are with the actual position. Neither of those first two effects would be seen when using negative margins.

Another technique that might be substituted for floats would be the use of absolute positioning, but it also would not create the "wrap around" behavior of inline elements like floats do.