Firefox, IE9+ issue with div height 100% inside a td (working example on Chrome)

前端 未结 1 1967
攒了一身酷
攒了一身酷 2021-01-18 08:39

Take this: http://jsfiddle.net/zVscL/4/

.edit-me {
height:100%; /*does not behave the same as Chrome*/
width:10px;
border:1px solid blue;
background:red;
flo         


        
相关标签:
1条回答
  • 2021-01-18 09:33

    Try setting the height of the tr and td to 100%:

    tr, td { height: 100%; }
    

    Generally speaking to get height: 100% to work correctly, all the heights of the element's parents must be set as well.

    EDIT:

    An alternative solution is to wrap the contents of the td with a container div and use absolute positioning to ensure the .edit-me div effectively has 100% height.

    Here's what the HTML would look like:

    <table border="1">
        <tr>
            <td>
                <div class="container">
                    <div class="edit-me"></div>
                    Foo
                    <br/>
                    Bar
                </div>
            </td>
            <td>hello</td>
        </tr>
    </table>
    

    and the CSS:

    .container {
        position: relative;
        padding-left: 10px;
    }
    
    .edit-me {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
    
        width:10px;
        border:1px solid blue;
        background:red;
        overflow: auto;
    }
    

    Hope this helps!

    0 讨论(0)
提交回复
热议问题