Reputation: 1521
I have this div on the CSS:
#bodycontent {
max-width:980px;
margin:auto;
}
#navleft {
width:18%;
border:0px;
float:left;
}
#rightcontent {
max-width:80%;
border:0px;
float:right;
}
and on the HTML:
<div id="bodycontent">
<div id="navleft">
some stuff
</div>
<div id="rightcontent">
some stuff
</div>
</div>
Now I have 2 problems:
Why? The padding is not inside?
Upvotes: 4
Views: 7065
Reputation: 12524
The problem you are facing is because of the box model. The width you declare is the width of the content and not the true width of the element.
To learn more about the box model
To change this so that the border and padding are all part of the elements width you can use border-box
#your-element {
-moz-box-sizing: border-box;
-webkit-box-sizing:
border-box; box-sizing: border-box;
}
Upvotes: 4
Reputation: 2184
Read about the css box model.
Your content is the inner-most box, and it will have the width
you specify. Padding, border, and margin are all added to this width. Padding will be inside the border, but not inside the content width.
Upvotes: 2
Reputation: 943175
The width
property is defined (in CSS 2) as the width of the content, not the space between the borders. Padding goes inside the borders, not inside the width.
In CSS 3, you can change this with the box-sizing
property but this has limited support.
Upvotes: 6