tags:

views:

32

answers:

2

I'm having a bit of a problem. I'm using FireFox 3.6 and have the following DOM structure:

<div class="view-row">
    <div class="view-type">Type</div>
    <div class="view-name">Name</div>                
</div>

And the following CSS:

.view-row {
width:100%;
display:table-row;
}

.view-name {
display: table-cell;
float:right;
}

.view-type {
display: table-cell;
}

If I take off the display:table-row it will appear correctly, with the view-row showing a width of 100%. If I put it back it shrinks down. I've put this up on JS Bin:

http://jsbin.com/ifiyo

What's going on?

A: 

give on .view-type class float:left; or delete the float:right; of .view-name

edit: Wrap your div <div class="view-row"> with another div for example <div class="table">

and set the following css :

.table {
    display:table;
    width:100%;}

You have to use the table structure for correct results.

Sotiris
Tried that, it did not work.
chum of chance
I tested with ff3.6, ie 8,chrome,opera. you can see it here http://jsbin.com/ifiyo/4 they show them side by side
Sotiris
I was looking to have name on the far right, type on the far left ... if you do a display:inline on both and take out the display:table-row it works, I was thinking there might be a better way to do it using the table-row/cell properties.
chum of chance
I edit my answer. check it.
Sotiris
+1  A: 

If you're using display:table-row etc., then you need proper markup, which includes a containing table. Without it your original question basically provides the equivalent bad markup of:

<tr style="width:100%">
    <td>Type</td>
    <td style="float:right">Name</td>
</tr>

Where's the table in the above? You can't just have a row out of nowhere (tr must be contained in either table, thead, tbody, etc.)

Instead, add an outer element with display:table, put the 100% width on the containing element. The two inside cells will automatically go 50/50 and align the text right on the second cell. Forget floats with table elements. It'll cause so many headaches.

markup:

<div class="view-table">
    <div class="view-row">
        <div class="view-type">Type</div>
        <div class="view-name">Name</div>                
    </div>
</div>

CSS:

.view-table
{
    display:table;
    width:100%;
}
.view-row,
{
    display:table-row;
}
.view-row > div
{
    display: table-cell;
}
.view-name 
{
    text-align:right;
}
KP
+5 on getting rid of the damn floats!
chum of chance