4

I have been creating a layout system in Javascript for application windows... The Javascript produces the code listed below...

Everything is working really well, except Firefox seems to have different rules for CSS tables than other browsers.

It seems that Webkit browsers set the context for sizing CSS table-cell elements to the nearest relatively/absolutely positioned parent element, just like normal elements, and from this we can treat each cell as a new context for sizing and positioning things absolutely.

Firefox does not appear to do it this way.

Here's sample code:

<div class="header"></div>
<div class='table'>
    <div class='row'>
        <div class='cell'>
            <div class='wrap'>
                <div class='pane'>
                Content here that is long enough to wrap at the sides. Content here that is long enough to wrap at the sides. Content here that is long enough to wrap at the sides.  And still hit the bottom.
                </div>
            </div>
        </div>
        <div class='cell' style='background-color:orange; width:230px;'>
            cell2
        </div>
    </div>
</div>

and css:

.header {
    height: 50px;
    width: 100%;
    background: blue;
}
.table {
    width:100%;
    height:200px;
    display:table;
}
.row {
    display:table-row;
}
.cell {
    display:table-cell;
    background-color:red;
    position:relative;
}
.wrap {
    display:block;
    position:absolute;
    background-color:purple;
    width:100%;
    height:100%;
}
.pane {
     background-color:green;
    height:100%;
    width:100%;
    position:absolute;    
}

Which can be viewed here: http://jsfiddle.net/XmUZ7/3/

This viewed in Webkit (Safari/Chrome) vs. Firefox/Mozilla exemplifies the issue.

I've tried adding a .wrap element into the cell but it doesn't seem to help reset the context. Am I thinking of this the wrong way? Other posts on SO seem to imply that the cell or the .wrap needs to be an inline-block, but those also don't seem to work.

Here are some other links related to this:

Positioning context on table-cell element in Firefox

css absolute position inside table-cell: strange Firefox display

CSS Positioning Absolute within table cells not working in Firefox

https://bugzilla.mozilla.org/show_bug.cgi?id=203225

At this point I am considering not supporting firefox because I've spent so many hours trying to fix it. But this seems silly because everything else is working well across browsers except for basic layout!

It feels like either there is a magic bullet I'm missing or that Firefox has deep design issues that will not allow this.

I think JSFiddle has gotten around this issue by using iframes and no tables at all in its layout, but it does imply there are bugs being avoided.

Community
  • 1
  • 1
Eyelash
  • 1,760
  • 2
  • 12
  • 18

2 Answers2

0

Your basic issue is that specifying position: relative on a table cell in Gecko does not make the cell a containing block for absolutely positioned kids. See https://bugzilla.mozilla.org/show_bug.cgi?id=63895

The spec's take on this is at http://www.w3.org/TR/CSS21/visuren.html#choose-position:

The effect of 'position:relative' on table-row-group, table-header-group, table-footer-group, table-row, table-column-group, table-column, table-cell, and table-caption elements is undefined.

What you want to do in the short term is put your position:relative on a block inside the cell (e.g. your "wrap" block).

Jeremy
  • 2,642
  • 18
  • 36
Boris Zbarsky
  • 34,758
  • 5
  • 52
  • 55
0

Yes, that is exactly the issue. It should be defined!

So, is it decided that the Gecko renderer will not reset the sizing context for children of tables (IE the meaningful bits, like cells, who may want to request 100% of width and height) like other renderers?

It seems like cells should be a sovereign space for new sizing...

Eyelash
  • 1,760
  • 2
  • 12
  • 18