Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
810 views
in Technique[技术] by (71.8m points)

css - Chrome doesn't honor row height if rowspan is present

I want to make a table with a cell that spans on two rows. The second row must have the height size as minimum as possible. Example:

html:

<table>
    <tr id="row-1">
        <td>
            1st row
        </td>
        <td rowspan="2">
            a <br />
            a <br />
            a <br />
            a <br />
            a <br />
            a <br />
            a <br />
            a <br />
        </td>
    </tr>
    <tr id="row-2">
        <td>
            2nd row
        </td>
    </tr>
</table>

css:

td
{
    border: 1px solid black;
}
#row-2
{
    height: 1px;
}

http://jsfiddle.net/xp7vz/

It works on Firefox (19.0.2). On Chromium (25.0.1364.160), the row with the minimum height is the first one!

EDIT: The problem is caused by this bug: http://code.google.com/p/chromium/issues/detail?id=78724

How can I hack it with CSS? Currently I'm using JS, setting the 1st row height equal to the height of the rowspan cell minus the height of the second row.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Found: the trick is to put another table inside a cell of the table with the non-rowspan content, remove the rowspan from the other cell and set the outer and inner table height to 100%. Horrible but effective.

HTML:

<table id="outer"><tbody><tr>
    <td>
        <table id="inner"><tbody>
            <tr id="row-1">
                <td>1st row</td>
            </tr>
            <tr id="row-2">
                <td>2nd row</td>
            </tr>
        </tbody></table>
    </td>
    <td>
        a<br />
        a<br />
        a<br />
        a<br />
        a<br />
        a<br />
        a<br />
        a<br />
        a<br />
    </td>
</tr></tbody></table>

CSS:

#row-2 
{
    height: 1px;
}
#outer, #inner 
{
    height:100%;
}

http://jsfiddle.net/xp7vz/3/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...