Centering left-floated items - how? Please help!

R

rudicheow

SHORT VERSION
=============

I have a bunch of identical fixed-size single-celled tables that rest
against each other horizontally thanks to "float:left". These tables
are dynamically generated and the number of them can vary greatly. They
are all contained within a parent table cell, which is centred on the
page. But I am unable to find a way of centering these table cells
within the parent cell.

I basically need to be able to have fixed-size image containers stacked
horizontally (which is why I use float:left), but to have those centred
(which float:left negates).

I've tried DIVs, and the behaviour is the same. Any ideas? Thanks.


LONG VERSION
============

I am building a couple of pages for a client that need to feature a row
hyperlinked images. The pages are being generated dynamically with a
PHP script pulling data from an XML file. This way my client doesn't
need to edit HTML - editing the XML file and uploading the image will
update the site. The page in question is here:

http://www.impala.org/promoterlist.php

The three logos visible are contained within single-cell tables, with
dimensions of 135x135 pixels each. They are floated left, which is why
they are horizontally next to each other. They are themselves nested
within a table which is centred in that section of the page.

My problem is that the three floating table cells are resting against
the left margin of the parent table cell. I want it to be centred.

The dimensions are all organised so that the parent cell nicely fits
four child tables, and then the fifth wraps to the next line and
carries on. When I have multiples of four logos in there, it looks
perfect. But I want what is there to be centred.

What is the best way of acheiving this?

It is important to bear in mind that the number of logos will change
and that the page is dynamically generated, so any solution will need
to work regardless of the number of logos and the code needs to lend
itself to replication by a script (i.e. using the script to generate a
table with multiple cells will not work because each loop must only
process one image and it needs to apply the same identical code to each
image).

Two fixes I've attempted:

1) Using DIVs instead of tables - exact same problem.

2) Trying to find a way to use CSS to create an "invisible box" around
an image of a set dimension and to anchor the centre point of that
image to the centre of that box. Not found anything. This would remove
the need for any layout code.

I know an easy way would just be to ensure each image is 135x135 pixels
and forget about using tables and DIVs, but that is not a burden I want
to give to my client.

I hope I've made things clear! Any help would be greatly appreciated.
 
H

Harlan Messinger

SHORT VERSION
=============

I have a bunch of identical fixed-size single-celled tables that rest
against each other horizontally thanks to "float:left". These tables
are dynamically generated and the number of them can vary greatly. They
are all contained within a parent table cell, which is centred on the
page. But I am unable to find a way of centering these table cells
within the parent cell.

I basically need to be able to have fixed-size image containers stacked
horizontally (which is why I use float:left), but to have those centred
(which float:left negates).

I've tried DIVs, and the behaviour is the same. Any ideas? Thanks.

Yes, do use DIVs, not one-celled tables.

To align the inline content *within* a block, use text-align: center.
 
J

Jim Moe

I have a bunch of identical fixed-size single-celled tables that rest
against each other horizontally thanks to "float:left". These tables
are dynamically generated and the number of them can vary greatly. They
are all contained within a parent table cell, which is centred on the
page. But I am unable to find a way of centering these table cells
within the parent cell.

I basically need to have fixed-size image containers stacked
horizontally (which is why I use float:left), but to have those centred
(which float:left negates).

I've tried DIVs, and the behaviour is the same. Any ideas? Thanks.
Drop the use of single-celled tables altogether. (Sounds like a biology
project.) There is no need to float the images or their containers.
Simply list the images in the parent table cell and set the cell's
justification attribute to "center". Place a space between <img>'s so they
will wrap within the cell.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Having trouble centering contents of td ? 3
Please help 2
Help please 8
HELP PLEASE 4
Code help please 4
Hello and Help please :-) 1
Total Purchase. Please Help 1
How to output accept items for repair 1

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top