I'm trying to use DIVs contained within a DIV to show content which is centered horizontally on the page, as per this example.
+=========== DIV 1 ===========+
+------+=====+=====+=====+-------+
+------+ DIV 2 + DIV 2 + DIV 2 +--------+
+------+=====+=====+=====+-------+
+==========================+
Here's the CSS and HTML code I'm using:
CSS
.DIV1 {
width: 100%;
margin-left: auto;
margin-right: auto;
height: 70px;
}
.DIV2 {
float: left;
text-align: center;
width: 80px;
}
HTML
<div class='DIV1'>
<div class='DIV2'>Content 1</div>
<div class='DIV2'>Content 2</div>
<div class='DIV2'>Content 3</div>
</div>
I've learnt that by setting margin-left and margin-right to 'auto' in DIV1 the content inside is centered, but only if it contains one DIV2 inside it.
When I add more DIV2s then the content inside DIV1 now shows on the left and ignores any centering...
+=========== DIV 1 ===========+
+=====+=====+=====+---------------+
+ DIV 2 + DIV 2 + DIV 2 +----------------+
+=====+=====+=====+---------------+
+==========================+
Does anyone please know why this is happening, and how I can fix it?
Thanks