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
Li Xia
4,671 PointsMargin
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
akc
11,729 PointsIt 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;
Elliott Frazier
Courses Plus Student 9,647 Pointsif you show us your code it'll be easier to diagnose the problem. :)
Li Xia
4,671 Pointsdisplay:inline-block; did the trick! thanks.
James Barnett
39,199 PointsThe short answer is:
- An
<a>element is inline, so you need to change its display to eitherblockorinline-blockso 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.
Li Xia
4,671 PointsI get what an inline element is, but what other elements are there?
James Barnett
39,199 PointsHere's a list of the various attributes for use with the CSS property display