CSS “outline” different behavior behavior on Webkit & Gecko

前端 未结 3 1145
我在风中等你
我在风中等你 2020-11-30 07:37

I\'m working on an experiment & I found out that the \"outline\" CSS2 property is not implemented the same way on Webkit & Gecko

In the script below, I have

相关标签:
3条回答
  • 2020-11-30 07:50

    I've fixed using this instead absolute positioning:

    transform: translate(x,y);
    

    .outer {
        position: absolute;
        top: 20px;
        left: 20px;
        height: 50px;
        width: 100px;
        background: blue;
        border: 3px solid green;
        outline: 3px dotted red;
    }
    .inner {
        position: absolute;
        transform: translate(80px, 15px);
        width: 40px;
        height: 20px;
        background: yellow;
    }
    <div class="outer">
        <div class="inner">
        </div>
    </div>

    0 讨论(0)
  • 2020-11-30 07:55

    This inconsistent behavior of Gecko is well-known and quite adequately documented, although strangely not at MDN but at the SitePoint Reference:

    Firefox up to and including version 3.5 will draw the outline outline around the content of an element that has overflowed its boundaries rather than around the element’s actual set dimensions.

    This continues to affect all versions of Firefox. I don't see a viable workaround for it at the moment, other than to remove your absolutely-positioned div from its parent and place it relative to... something else.

    0 讨论(0)
  • 2020-11-30 08:07

    I had the same issue, so I swapped it from using outline to use a box-shadow:

    box-shadow: 0px 0px 0px 1px #FFF;
    

    instead of

    outline:1px #dcdcdc solid;
    
    0 讨论(0)
提交回复
热议问题