Old 08-07-2004, 07:16   #1 (permalink)
stickmus
hmmm...
 
stickmus's Avatar
 
Join Date: Jan 2004
Location: Yorkuk
Posts: 2,127
Centering a floated div...

I've been trying to get this to work for a while, but with no results.

http://www.mistercut.com/test/ferrara/index.html

http://www.mistercut.com/test/ferrara/ferrara.css


What it does is great: the div only expands when there's enough room for the next float.

But ideally I would like it centered on the page too.

Any suggestions?

I've tried putting it in a container div, but wasn't sure what styles might make it work.
  Reply With Quote
Old 08-07-2004, 12:05   #2 (permalink)
adras
Zły
 
adras's Avatar
 
Join Date: May 2004
Location: Toronto, Canada
Posts: 2,001
Send a message via MSN to adras
add this to the container div

margin: auto;

that's should center it..
__________________
  Reply With Quote
Old 09-07-2004, 03:36   #3 (permalink)
stickmus
hmmm...
 
stickmus's Avatar
 
Join Date: Jan 2004
Location: Yorkuk
Posts: 2,127
Quote:
Originally Posted by adras
add this to the container div

margin: auto;

that's should center it..

Yeah I tried that.

Should but doesn't as you can see.
  Reply With Quote
Old 09-07-2004, 04:03   #4 (permalink)
Bill Posters
trouble free and loverlee
 
Join Date: Mar 2003
Location: YooKay
Posts: 2,933
Code:
body { text-align: center; /* needed for certain non-compliant browsers */ … } #container { margin: 0 auto; /* used for compliant browsers */ width: ??px; /* you need to declare a width */ text-align: left; /* resets the text-alignment after the earlier workaround */ … }

Without a width the container div will simply use its default width which is 100% of its parent element, in this case, the html/window.
The width of the container needs to be less than that of the window as you can't center something that already fills the available space.
  Reply With Quote
Old 09-07-2004, 07:06   #5 (permalink)
stickmus
hmmm...
 
stickmus's Avatar
 
Join Date: Jan 2004
Location: Yorkuk
Posts: 2,127
That nearly works...but:

If you use a small width, then the auto-wrapping doesn't work. And if you use a big one (oo-er) it's only centered at the point where it wraps.

Arrgh!
  Reply With Quote
Old 09-07-2004, 07:17   #6 (permalink)
Bill Posters
trouble free and loverlee
 
Join Date: Mar 2003
Location: YooKay
Posts: 2,933
*ahem*

Quote:
Originally Posted by my example
…container {
margin: 0 auto;
text-align: left;

}
Quote:
Originally Posted by your current markup
…container {
margin: auto;
text-align: center;

}
  Reply With Quote
Old 09-07-2004, 07:24   #7 (permalink)
stickmus
hmmm...
 
stickmus's Avatar
 
Join Date: Jan 2004
Location: Yorkuk
Posts: 2,127
Okay, but that doesn't make a difference. (not even in ie5).
  Reply With Quote
Old 12-07-2004, 03:44   #8 (permalink)
stickmus
hmmm...
 
stickmus's Avatar
 
Join Date: Jan 2004
Location: Yorkuk
Posts: 2,127
Any more for any more?

I've simplified it all down at:
http://www.mistercut.com/test/floatbox.html

Thanks
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8