...

View Full Version : Confused about margins



mattshiao
08-14-2010, 07:14 PM
Hi,

I have a really dumb question. Given the following css and html:

<style>
li {margin: 5px;}
</style>
<ul>
<li id="item1">Item 1</li>
<li id="item2">Item 2</li>
</ul>

What is the margin between item1 and item2? 5px or 10px?

Seems to me item1 has a margin-bottom of 5px and item2 has a margin-top of 5px, that should add up. Do I completely misunderstand how margins work?

TIA

SB65
08-14-2010, 07:40 PM
The specs say that margins should collapse between adjacent elements - so in this case the margin should be 5px.

This is a good explanation. (http://reference.sitepoint.com/css/collapsingmargins)

jdswebservice
08-15-2010, 04:19 PM
Also don't forget when you are using:


#something {
margin: 5px;
}

You are saying you want 5px on ALL sides of that element. so you have 5px on the top, left, bottom, and right places of that element.

J-



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum