views:

124

answers:

1

I have a table with 1 row and 5 columns. I have fixed the width of those 5 columns to certain known values (150px, 200px etc..). I have also set the left-margin for each one.

I want the table to widen and occupy the entire width of its parent. So, I set its width to 100%. When the table is wider than the combined width and margins of the 5 columns, it causes them to spread out across the table leaving gaps in between.

But, I want those 5 columns to stay on the left.

To achieve this, I added a 6th column and set its width to auto, hoping that it will properly push the first 5 to the left and occupy the remaining space. It works in Firefox and Chrome. But it doesn't work in IE. In IE, the 5 columns still space themselves evenly across the table.

I tried setting the width of the 6th column to 100% instead of auto. But the problem is, it is wiping out the left-margins of the 5 columns! Sort of like, the 100% column is pushing the 5 columns too much to the left that their margins have disappeared!

I want the padding, margin and width of the first 5 columns to be maintained, but pushed to the left, yet the table should expand as wide as its parent.

The table has a background image that needs to show up beyond the 5 columns.

Some might suggest that I move the background to the table's parent, but I can't - take my word for it :D

How can I get this to work in Firefox, Chrome and IE?

Thanks.

Here is the link : http://test.greedge.com/table/table.php. Try it in FF and IE

+1  A: 

Edit: The solution is simple: Add a   to the one td in the table in the last column. The table cell of the inlying table is not rendered, because it contains nothing. Thus, the last cell also contains nothing, does not get rendered, and the other cells have to split the available space amongst them.

I don't know which browser is doing the right thing here, all IE's (including 8) don't render the column, all other browsers do.

Old answer:

Columns aren't supposed to have margins according to the CSS 2.1 spec:

margin-right, margin-left

Applies to: all elements except elements with table display types other than table-caption, table and inline-table

You will need to use padding within the cells.

An auto column should work in any browser in the scenario you describe (just don't specify any width). Can you post an online example of a table that doesn't work?

Pekka
It could take me a while to post an online one that you can have a look at. I'll let ya know when I am done setting it up.
@iam all right. Before you do that, maybe check a second time whether you definitely have given all the `td` s fixed widths, and the 6th one no width at all. That should work fine.
Pekka
@iam also remove the margins first, it could be that IE (wrongly) interprets them.
Pekka
Ok to be compliant, I replaced margins with padding. Still IE interprets 'auto' differently and they spread across the table.I checked again. auto spacing doesn't work in IE. The columns still spread across the table.
@iam-developer really, really odd. If you post it online, I'll take a look at some point during the day. (Day as in GMT :)
Pekka
here is my problem - perfectly reproduced - http://test.greedge.com/table/table.php
@iam I figured it out, see my edited answer.
Pekka
It worked! I used to do that, but when the height of the elements got shorter than the height of  , it created problems. So, whenever I didn't want to leave empty space inside a container, I started using <b></b> since it didn't occupy any real height. But in this case it didn't work and using   fixed the problem. But can you comment on what is going on?
@iam `<b></b>` in itself is no character data = nothing to display. Try `<b> </b>` that should work.
Pekka
@iam-developer Almost: An image or `<hr>` would work as well as a character. Any content will do.
Pekka
Just saw your answer. You're right, I don't know which browser is doing the right thing.