Enlighten me a question:
If I put a div inside another, in this second div I can’t use the properties margin-left and margin-top without changing the position of parent div?
I need to use padding instead??
EXEMPLE:
FIDDLE WITH MARGINS: http://jsfiddle.net/zyEYj/1/
FIDDLE WITHOUT MARGINS: http://jsfiddle.net/zyEYj/2/
FIDDLE WITH PADDING INSIDE MOTHER DIV: http://jsfiddle.net/zyEYj/3/ (this is the final effect i want, but i need to use padding, and change the height of #header)
codes:
<div id="header" class="container">
<div class="logo">
<a href="index.asp"><img src="imagens/logo.png" /></a>
</div>
</div>
css:
body{
background:#d3f1fc;
}
#header{
height:135px;
background:#ee4b14;
padding-top:35px;
padding-left:21px;
}
.container {
margin:0 auto;
width:960px;
}
.logo{
width:382px;
height:114px;
background:#FFCC00;
}
This behavior is referred to as
margin collapse. Two adjacent margins will collapse into one another, with the higher absolute value taking precedence.This can be defeated either by separating the margins (via
paddingorborderon the parent element), or by usingposition: relativeon the child element, and adjusting its position that way.HTML:
CSS:
Normal
Padding/Border solution
Position: relative solution