I'm sort of a CSS philistine, but off the top of me head... It overlaps because the size of the box is
left margin + left border + left padding + width + right padding + right border + right margin.
So with width as 100%
- margin: auto will be the same as "margin:0" -- no problem there
But width:100% + border: 2px means that your box size is 100% + 2px. Since you're already at 100%, there's no place for the 2 pixels to but just outside the box.
So let's say that your containing box that holds "content1" is 100px. What I would expect is (again, not tested and I am not usually daring enough to do CSS in my head)
- content1 should be
-- left border is at pixels 1+2
-- content box is at pixels 3-102
-- right border is at pixels 103-104
- content 2 should be
-- left border is at pixels 3-4
-- content box is at pixels 5-104
-- right border is at pixels 105-106
It sounds like what you're getting is
- content1 should be
-- left border is at pixels 1+2
-- content box is at pixels 3-100
-- right border is at pixels 101-102
- content 2 should be
-- left border is at pixels 3-4
-- content box is at pixels 5-100
-- right border is at pixels 101-102
If you were using Internet Explorer 6 or earlier and did not have a DOCTYPE as your very first line, you would have triggered quirks mode [google.com] and you should get
- content1 should be
-- left border is at pixels 1+2
-- content box is at pixels 3-98
-- right border is at pixels 99-100
- content 2 should be
-- left border is at pixels 3-4
-- content box is at pixels 5-96
-- right border is at pixels 97-98