td { position:relative; } overflows into the table border

后端 未结 4 1253
梦谈多话
梦谈多话 2020-12-10 00:51

http://jsfiddle.net/L83y3/

HTML

stuff more stuff
相关标签:
4条回答
  • 2020-12-10 01:37

    Apply z-index:-1;

    jsfiddle: http://jsfiddle.net/thilakar/L83y3/1/

    .right
    {
        position:relative;
        z-index:-1
    }
    
    0 讨论(0)
  • 2020-12-10 01:40

    You can't reliably change the position of a table cell, some browsers (older Safari versions at least, the latest one seems to have fixed this problem) will force table cells (and rows) to position: static no matter what you say.

    If you need to absolutely position something inside a table cell, you'll need to put a relatively positioned <div> (or other block element) inside the cell and then put everything else inside that:

    <table>
        <tr>
            <td>stuff</td>
            <td><div class="right">more stuff</div></td>
        </tr>
    </table>
    

    And then tweak the CSS:

    .right {
        position:relative;
        width: 100%;
        height: 100%;
    }
    

    And the obligatory live example: http://jsfiddle.net/ambiguous/KUshG/

    I suspect that takes care of the problem you're seeing and does away with some problems that you haven't seen yet.

    0 讨论(0)
  • 2020-12-10 01:47

    Background clipping just did the trick. Just apply "background-clip: padding-box;" on the th and it works.

    according to the docs: https://developer.mozilla.org/en-US/docs/Web/CSS/background-clip.

    "No background is drawn below the border (background extends to the outside edge of the padding)."

    0 讨论(0)
  • 2020-12-10 01:52

    Don't use position on table-cells.

    Just wrap the cells content into a relative div:

    <table>
        <tr>
            <td>stuff</td>
            <td class="right">
                <div style="position:relative;">more stuff</div>
            </td>
        </tr>
    </table>
    
    0 讨论(0)
提交回复
热议问题