Re: Percentage Height of a Replaced Element in a Table Cell

Le Mar 7 août 2012 17:19, Robert Hogan a écrit :
> Hi CSS Test,
>
> Browsers disagree on how to render this snippet:
>
>         <table style="width:20px;height:20px">
>             <tr>
>                 <td style="width:100%;height:100%"><img
> src="50x50.png"></td>

In your snipped, the percentage is applied onto the table cell and not
on the replaced element.

"
CSS 2.1 does not define how the height of table cells and table rows is
calculated when their height is specified using percentage values.
"
17.5.3 Table height algorithms
http://www.w3.org/TR/CSS21/tables.html#height-layout



>             </tr>
>         </table>
>
> WebKit, FF: the image is rendered as 50x50

Table and table cells' default overflow property is set to visible. So,
the 50x50 image should be visible regardless of the dimensions of the
cell.

Overflow applies to table cell. IIRC, overflow also applies to table boxes.

> IE, Opera: the image is rendered as 20x20
>
> I believe IE and Opera are correct here: "The percentage is calculated
> with
> respect to the height of the generated box's containing block." Going up
> the chain this is 20px.
>


Width for table when resorting to 'table-layout fixed' algorithm (for
both border-collapse models):

"The width of the table is then the greater of the value of the 'width'
property for the table element and the sum of the column widths (plus
cell spacing or borders). If the table is wider than the columns, the
extra space should be distributed over the columns.
"
17.5.2.1 Fixed table layout
http://www.w3.org/TR/CSS21/tables.html#fixed-table-layout


Robert, it would be best to create a full, accessible testpage from your
snippets and to use+declare 'table-layout: fixed'.



> This is distinct from the following case, where rendering 50x50 would be
> the right thing to do:
>
>         <table>
>             <tr>
>                 <td style="width:100%;height:100%"><img
> src="50x50.png"></td>
>             </tr>
>         </table>
>
> "If the height of the containing block is not specified explicitly
> (i.e.,
> it depends on content height), and this element is not absolutely
> positioned, the value computes to 'auto'."

One important question is: what is the containing block of a table cell?
Does the concept of containing block apply to table cell?

Gérard

>
> Am I right in thinking this?
>
> Thanks,
> Robert





-- 
Contributions to the CSS 2.1 test suite:
http://www.gtalbot.org/BrowserBugsSection/css21testsuite/

CSS 2.1 Test suite RC6, March 23rd 2011:
http://test.csswg.org/suites/css2.1/20110323/html4/toc.html

CSS 2.1 test suite harness:
http://test.csswg.org/harness/

Contributing to to CSS 2.1 test suite:
http://www.gtalbot.org/BrowserBugsSection/css21testsuite/web-authors-contributions-css21-testsuite.html

Received on Tuesday, 7 August 2012 21:44:39 UTC