I'm trying to wrap my head around how css margins interact with divs and their child elements.
For instance, when I set it up like this...
<div style="clear: both; margin-top: 2em;">
<input type="submit" value="Save" />
</div>
...the Save button ends up right next to the User Role (margin fail):
Margin Fail :( http://img697.imageshack.us/img697/8459/nomargin.jpg
But changing it to this setup...
<div style="clear: both;">
<input style="margin-top: 2em;" type="submit" value="Save" />
</div>
...creates a gap between the Save button and the User Role (margin win):
Margin Win :) http://img20.imageshack.us/img20/1973/yesmargin.jpg
Questions:
Can someone help me understand why the div
's margin doesn't push the input
element down? Why is it necessary to apply the margin directly to the input
? Is there a core principle of CSS that I am missing here?