Welcome to WebmasterWorld Guest from 54.226.27.104

Forum Moderators: not2easy

Message Too Old, No Replies

Centering floats?

Is that a contradiction in terms?

     

photon

9:49 pm on Feb 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a set of "address cards" that are set up as floats, all uniformly sized, so that they'll line up nicely in rows no matter the width of the screen. What I'd like to do is have the "cards" centered on the page (or within the containing div) regardless of whether there are one, two, three, or n across. Right now they tend toward the right side of the page since, of course, they're floated right.

Is it possible to center a group of block elements while still having a fluid number of them in a single row?

If the "card" concept isn't clear, think of them as thumbnails

DrDoc

10:51 pm on Feb 7, 2003 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Just wrap an extra div around them, setting its margin to auto ..

Or, if the div is 400px wide (for example), set left to 50% and leftmargin to -200px (negative the half width). That would center the box on the page ..

photon

6:27 pm on Feb 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



DrDoc-

I'll play with that idea some when I next get the chance. But I'm wondering how exactly that would work. Wouldn't I have to use a div with no declared width? That way the div would expand and contract to exactly fit the floats. Otherwise, with a declared width, the floats would still be off to one side. And, if so, does the

margin:auto
cause problems for IE?

So I'm thinking something like this (greatly reduced):


.fixedwidth {width:80%;}
.floatcontainer {margin:auto;}
.floater {display:block; float:right; width:20em;}
...
<div class="fixedwidth">
<div class="floatcontainer">
<span class="floater">blah blah blah</span>
<span class="floater">blah blah blah</span>
<span class="floater">blah blah blah</span>
</div>
</div>

Is that along the lines you were thinking?

 

Featured Threads

Hot Threads This Week

Hot Threads This Month