Google Chrome bug with tr background

后端 未结 11 2010
天命终不由人
天命终不由人 2020-12-16 11:32

I\'m trying to set a background-image to a table row, but background is applied to all its td children.

In IE7 there is the same bug but it is solve with

<         


        
相关标签:
11条回答
  • 2020-12-16 12:23

    Spent two days on this problem, finally found the answer here:

    You need to set:

    background-attachment: fixed;
    

    Not sure why the mods are deleting this answer, its not on the page.

    0 讨论(0)
  • 2020-12-16 12:26

    I'd recommend to set the background-image for the table-cells directly, shifting the background-position of all subsequent cells to the left so that it looks as it should. This way you don't have to slice your background-image.

    0 讨论(0)
  • 2020-12-16 12:27

    Here's my jQuery solution. It's for a thead tr but should work for tbody tr's as well.

        $(document).ready(function () {
        // Apply <thead><tr> background row fix for Chrome/Safari (webkit)
        if ($.browser.webkit) {
            $('thead tr').each(function (i) {
                var theadWidth = $(this).width()-1;
                $(this).append('<div style="position:absolute;top:'+$(this).position().top+'px;left:'+$(this).position().left+'px;z-index:0;width:'+theadWidth+'px;height:'+($(this).height()+8)+'px;background:#2e4b83 url(th_background.jpg) no-repeat 0 0;background-size:'+theadWidth+'px 100%;"></div>');
            });
        }
    });
    

    You can check it out in Chrome/Firefox/IE9. It should appear the same.

    0 讨论(0)
  • 2020-12-16 12:28

    This is the only solution I am aware of without using JavaScript. It has the shortcoming of you specifying the height of the TR and the TD, because the TR is positioned absolute. I am also not sure how it will behave in other browsers.

    <style>
        tr {
            position: absolute;
            background: url(http://www.google.com/intl/en_ALL/images/logo.gif) no-repeat;
            height: 200px;
            border: 1px solid #00f;
        }
        td {
            width: 200px;
            height: 200px;
            border: 1px solid #f00;
        }
    </style>
    
    <table cellpadding="0" cellspacing="0">
        <tr>
            <td></td>
            <td></td>
        </tr>
    </table>
    
    0 讨论(0)
  • 2020-12-16 12:34

    It should fix the tr background for Chrome and FF:

    table.header_table tr#row_1 {    
        display:flex;
    }
    
    0 讨论(0)
提交回复
热议问题