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

HTML

Margin

Following the css tutes where nick uses margin to push the BROWSE OUR CUPCAEKS down.

I have the same code, using chrome or safari and margin has no effect in the btn class selector. But margin does work when inline in the .html.

Double checked by downloading the project files and modifying this margin value, but i has no effect either.

Does any know why applying margin in a separate css file has no effect?

5 Answers

It has to do with collapsing margins and the way the "intro" and ".btn" selector interact within the same block. You can find more information on W3C spec 8.3.1.

Try adding this line in the .btn class selector and it should work:

display:inline-block;

if you show us your code it'll be easier to diagnose the problem. :)

display:inline-block; did the trick! thanks.

The short answer is:

  • An <a> element is inline, so you need to change its display to either block or inline-block so you can apply a margin to the top & bottom.
  • The margins are collapsing, because that's what margins are supposed to do, set your margins accordingly

This is the first in a series of courses about using CSS, the reasons behind this behavior will be covered later in the series.

You can read up on the differences between inline & block-level elements in this blog post.

I get what an inline element is, but what other elements are there?