1

Problem seems to be 'common', but among plenty of discussions I've seen I did not find nor acceptable solution nor strong reason why this not possible at all according to 'standards'.

Problem statement is

  • There is block in HTML whose external dimensions I can control - both width and height
  • Within this block I have first line with content of variable height, and I need this content to be visible completely (i.e. autosize without scrolling or clipping) ...
  • ... and second line - it should completely take the rest of space in parent block and overflow is OK to be scrolled.

I remember it was working some time ago (when setting first TR to 1px it actually gets expanded exactly to height needed to fit the content, second TR takes the rest of height), but trying to test it now in current major browsers I see it does work only in Chrome.

So the question is - is that layout possible to be achieved within HTML5/CSS3/cross-browser standards (with or without TABLEs). As you can see on screenshot both FF and IE do not control 'correctly' (i.e. as I expect) height of the embedded DIV with 'red' background.

Below is screenshot and jsfiddle for the problem.

Screenshot for the problem

And sample HTML

<div style="width: 200px; height: 200px;">
    <table style="height: 100%; border: 1px solid blue;">
        <tr>
            <td style="height: 1px; background: green; border: 1px solid magenta;">
                Variable Number<br/>
                Of Lines<br/>
                All should be visible<br/>
            </td>
        </tr>
        <tr>
            <td style="border: 1px solid magenta;">
                <div id="subject" style="height: 100%; background: red; overflow-x: hidden; overflow-y: auto">
                    Variable<br/>
                    Number<br/>
                    Of Lines<br/>
                    Overflowing <br/>
                    lines<br/>
                    Can be scrolled<br/>
                    ...<br/>
                    Variable<br/>
                    Number<br/>
                    Of Lines<br/>
                    Overflowing <br/>
                    lines<br/>
                    Can be scrolled<br/>
                    ...<br/>
                </div>
            </td>
        </tr>
    </table>
</div>
Xtra Coder
  • 3,389
  • 4
  • 40
  • 59

1 Answers1

0

Yet trying to find the way to "make it work" I've got to following question, which seems to be indirectly but closely relevant - HTML <tr> tag and position:relative. It says that TR and TD elements cannot be relatively-positioned

http://www.w3.org/TR/CSS21/visuren.html#propdef-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.

I guess this implies that these elements cannot create own blocks, because otherwise after setting "position: relative" on TD I would be able to absolutely position child DIV via "position: absolute; top: 0; left; 0; right: 0; bottom: 0".

...

Not sure how this co-exists with another part of 'standards' ...

http://www.w3.org/TR/CSS2/visuren.html#block-formatting

block containers (such as inline-blocks, table-cells, and table-captions) ... establish new block formatting contexts for their contents.

... in my understanding, 'block formating context' creates some container where I can set following style on single child DIV "position: absolute; top: 0; left; 0; right: 0; bottom: 0" and it will take whole content of the parent (TD in my case). This does not work too. I can't see reason behind this (most probably because nor TD not TR are relatively-positionable).

...

And the final thing - regarding %-units in height spec says http://www.w3.org/TR/2002/WD-css3-box-20021024/#the-ltlengthgt

A 'percentage' is relative to the computed value of the width or height of the containing block, but if that value is 'auto' the computed value for the percentage is also 'auto'.

... http://www.w3.org/TR/2002/WD-css3-box-20021024/#containing

The containing block of a normal-flow element or of a floating element is the content area of the nearest ancestor that is either a flow root or a block-level element.

In my case - after setting some fixed height on TD, 100% on child DIV is still calculated as 100% from whole table height, not TD height. Bug in FF and IE? Or am I misreading the 'standards'? ...

...

Damn ... those dummy standards make developer's life so hard ... PS: I'm now recalling - "some time ago" is back to IE5 and IE6. That case works in current IE the same way like current Chrome when switching to "IE5 quirks" mode. Now, with dummy 'standards' I've to find workaround for artificially introduced problems ...


Summary: after digging and trying to solve the problem during the day I have to admit - this is not possible to implement in a 'standards' way. I'll have to resort to JavaScript (what will cause some amount of lags and flickering :().

Community
  • 1
  • 1
Xtra Coder
  • 3,389
  • 4
  • 40
  • 59