Box Shadow on table row not appearing on certain browsers

后端 未结 9 1791
夕颜
夕颜 2020-11-27 18:44

CSS box-shadow on table rows - tr - doesn\'t seem to be working consistently across browsers. On some browsers the shadow is displayed; on others, there is no s

9条回答
  •  醉酒成梦
    2020-11-27 19:05

    I had the same issue. I was trying to highlight an entire row when the mouse was over it. Below is the css code for it:

    tr:hover {
        outline: none;
        -webkit-box-shadow: inset 0 0 10px #337AB7;
        box-shadow: inset 0 0 10px #337AB7;
    }
    

    It works fine on Mozilla Firefox (38.0.1) and Internet Explorer (11.0.9600.17801), both on Windows 7. However, did not work on Chrome (43.0.2357.81).

    Therefore, I had to workaround and I did a mix of the answers of Sviatoslav Zalishchuk and David Winiecki. As an result I got:

    @media screen and (-webkit-min-device-pixel-ratio:0) {
        tr:hover td:first-child {
           box-shadow: inset 0px 11px 8px -10px #337AB7, 
                       inset 0px -11px 8px -10px #337AB7, 
                       inset 11px 0px 8px -10px #337AB7;
        }
    
        tr:hover td {
           box-shadow: inset 0px 11px 8px -10px #337AB7, 
                       inset 0px -11px 8px -10px #337AB7;
        }
    
        tr:hover td:last-child {
           box-shadow: inset 0px 11px 8px -10px #337AB7, 
                       inset 0px -11px 8px -10px #337AB7, 
                       inset -11px 0px 8px -10px #337AB7;
        }
    }
    
    tbody > tr:hover {
        outline: none;
        -webkit-box-shadow: inset 0 0 10px #337AB7;
        box-shadow: inset 0 0 10px #337AB7;
    }
    

    That works fine and it does not break the column width of the table and still working on Mozilla and Explorer.

    Below there is a full example:

    table {
      box-sizing: border-box;
      border-collapse: collapse;
    }
    td,
    th {
      padding-left: 10px;
      padding-right: 10px;
      border: 1px solid #ffffdffffd;
      font: 14px;
      text-align: left;
    }
    
    /*To work only on Chrome and Safari*/
    @media screen and (-webkit-min-device-pixel-ratio:0) {
      tr:hover td:first-child {
        box-shadow: inset 0px 11px 8px -10px #337AB7, 
          inset 0px -11px 8px -10px #337AB7, 
          inset 11px 0px 8px -10px #337AB7;
      }
    
      tr:hover td {
        box-shadow: inset 0px 11px 8px -10px #337AB7, 
          inset 0px -11px 8px -10px #337AB7;
      }
    
      tr:hover td:last-child {
        box-shadow: inset 0px 11px 8px -10px #337AB7, 
          inset 0px -11px 8px -10px #337AB7, 
          inset -11px 0px 8px -10px #337AB7;
      }
    }
    
    /*To work on the others browsers*/
    tbody > tr:hover {
      outline: none;
      -webkit-box-shadow: inset 0 0 10px #337AB7;
      box-shadow: inset 0 0 10px #337AB7;
    }
    Name Born City
    David Gilmour 6 March 1946 Cambridge, England
    Roger Waters 6 September 1943 Surrey, England
    Nick Mason 27 January 1944 Birmingham, England
    Richard Wright 28 July 1943 London, England

提交回复
热议问题