Remove 1px transparent space from CSS box-shadow in IE11?

前端 未结 7 810
一整个雨季
一整个雨季 2021-01-01 16:57

I\'m using CSS box-shadow to mimic a background that \"bleeds\" to the edges of the browser window. It works great in Chrome, Firefox, Safari, and Internet Exp

相关标签:
7条回答
  • 2021-01-01 17:56

    Now that we know it's a bug, here's one acceptable workaround:

    .widget {
        width:600px;
        height:400px;
        margin:0 auto;
        text-align:center;
        background:white;
        box-shadow:20em 0 0 0 white, -20em 0 0 0 white;
        position:relative;
        z-index:2;
    }
    .widget:before, .widget:after {
        position:absolute;
        content: " ";
        width:1em;
        left:-1em;
        top:0;
        height:100%;
        background:white;
        z-index:1;    
    }
    .widget:after {
        left:auto;
        right:-1em;
    }
    

    Basically, I'm adding absolutely positioned :before & :after pseudo elements that contain nothing more than the same background color as the widget DIV and that DIV's box-shadow. These pseudo elements are offset just to the outside-left and outside-right of the widget DIV and positioned behind it so that they provide the correct color for the box-shadow bleed through.

    Obviously this adds complication if one is already using the :before & :after elements, but this works for my purposes. I suppose one could also try setting negative margins on the widget DIV.

    Checkout the fiddle here: http://jsfiddle.net/TVNZ2/

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