简体   繁体   中英

HTML: td not 100% table height

I've got the following problem:

I have a HTML <table>, which has a fixed height of 100px and no border. Inside this table, I've got one single row (100% height) and inside the row 5 td's (also with a height of 100%). Inside this td I have a div (position=relative, height=100%).

When I analyze the whole thing with the Chrome dev tool, I see, that the div's height is slightly smaller than the table. How can I set the div's height to be as great as the table?

I've already tried to set the cellpadding to -2px but it didn't work - I'm not really working with tables, so please forgive my lack of knoledge in this area :/

Thank you for your help

Edit: my source code:

<table>
    <tr>
        <td>
            <div>text 1</div>
        </td>
        <td>
            <div>text 1</div>
        </td>
        <td>
            <div>text 1</div>
        </td>
    </tr>
</table>

and the CSS:

table{
    padding: 0;
    margin: 0;
    height: 100px;
    width: 100%;
}

tr,
td{
    padding: 0;
    margin: 0;
    height: 100%;
    width: 200px;
}

td > div{
    padding: 0;
    margin: 0;
    position: relative;
    height: 100%;
    width: 100%;
}

You only need to set cellpadding and cellspacing to 0:

<table cellpadding="0" cellspacing="0">

See: http://jsfiddle.net/darekkay/bdej1qgw/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM