tags:

views:

70

answers:

5

Hi,

I have a html table that has 2 cells in a row. How can i make the second cell appear below the first one instead of next to it? I can only do it in css and it's a dirty hack, but ... i still need it.

+1  A: 

change the display to block tr td{ display:block; }

pleasedontbelong
A: 

With out affecting the whole table it's not possible.

You can set the display of the table cells to block:

#your-table-id, #your-table-id tr, #your-table-id td {
  display: block;
}

You could try this with only the row you want, but those cell will most likely be renders after the rest of the table.

Edit: Actually it dies work with just a row: http://jsfiddle.net/JzkLZ/

Caveat: This won't work in IE6.

RoToRa
Caveat 2: This wont work in IE8
Midhat
@Midhat: True...
RoToRa
A: 

CSS:

table{
    width: 100px;
}
.block{
    border: 1px solid black;
    display: block;
    width: 100px
}

HTML:

<table>
    <tr>
        <td class="block">
            First Cell
        </td>
        <td class="block">
            Second Cell
        </td>
    </tr>
</table>

Try it: http://jsfiddle.net/LKFC5/1/

If possible you should try to edit the HTML instead of hacking it with CSS :)

Michael Robinson
Not IE compatible
Midhat
It doesn't work on IE ... already tried it
Marius S.
A: 

Add these to the cell style to make it work in IE:

float:left;
clear:both;
Ray
Hm, it seems that a simple float:left on both cells does the job. Thanks for the idea!
Marius S.
the float by itself works if you explicitly set the table and cell widths to force each cell to a new line. If you have auto width on the table and cells, you will need the clear:both.
Ray
A: 

How your code look like?

I would rather use jQuery not CSS

giker
I'd rather write correct implementation so that i woulnd't have to hack it. How many times will i have to repeat that i can't.
Marius S.
I'm afraid you can't do that only with CSS
giker