Hello..
I’m having a little problem with padding with auto margin on sides of a div.
Probably good idea to start with the code I am having problem with.
[code]
<html>
<head>
<style>
#test1
{
width:300px;
margin:0 auto;
padding: 0 20px;
background: #fcf897;
border:1px solid;
}
#test2
{
width: 300px;
margin:0 auto;
padding:0;
background: #c9e0f7;
border:1px dashed;
}
</style>
</head>
<body>
<div id=”test1″>Test1 div
</div>
<div id=”test2″>Test2 div
</div>
</body>
</html>
As you see those 2 divs above have the same width, and I added some padding on test1 div thinking that would make the wording inside the div have a little breathing room from sides of the div and maintain the same width.
Instead, the padding actually expanded the div to the sides by the amount of the padding. (Try the code yourself on your browser.)
I don’t understand what went wrong.
(I’m kind of guessing this has something to do with the ‘auto’ margin though.)
Any idea will be appreciated.