Forum Moderators: not2easy
Something similar to this post [webmasterworld.com], but with the ability to put block elements within the final nested div.
Anyone have any ideas?
<style>
.fixed {width:700px; background-color:red}
.center {float:left; width:100px; background-color:blue}
</style>
<div class="fixed">
<div class="center">
<ul>
<li>one</li>
<li>two</li>
</ul>
</div>
<div class="center">
<ul>
<li>one</li>
<li>two</li>
</ul>
</div>
</div>
I'm looking to center the blue divs within the red ones, which in itself is relatively easy. However, because this code is ultimately going to be dynamic, there could be 1,2 or 3 "center" divs. So, I require a solution which allows for the divs to remain centered within the "fixed" div regardless of the number of "center" divs.
.outer { width:700px; text-align:center; background:red; }
.inner { float:left; width:100px; background:blue; }
<div class="outer" style="margin-left:-150px;">
<div class="inner"></div>
<div class="inner"></div>
<div class="inner"></div>
</div>
You do have to add another div...but no need for negative margins (although it *is* an option...but it's easier to just put in another div...) like so:
<style>
body {
text-align:center;
}
.fixed {
width:700px;
background-color:red;
}
.outer {
display:table;
margin:0 auto;
}
.center {
float:left;
text-align:left;
width:100px;
background-color:blue;
}
hr {
clear:left;
visibility:hidden;}
</style><body>
<div class="fixed">
<div class="outer">
<div class="center">
<ul>
<li>one</li>
<li>two</li>
</ul>
</div>
<div class="center">
<ul>
<li>one</li>
<li>two</li>
</ul>
</div>
<hr />
</div>
</div>
</body>
</div>
Hope that helps ya!
Anyway, SuzyUK posted this post about centering floats [webmasterworld.com] last year. Interesting.