0

I am working with css outline property, and I found that it is working differently between Chrome and Firefox if descendant elements are outside.

  • in Chrome, outline is only for itself range, even though any descendant elements are outside of itself area.

results in chrome: blue rectangle has an outline, descendant green rectangle has not

  • in Firefox, outline is all range including all descendant elements. results in Firefox: Bounding box of both blue and green has the outline

<div style="
    margin: 100px;
    width:  100px;
    height:  100px;
    background: blue;
    outline: solid 1px red;
    position:  relative;">
  <div style="
        width: 100px;
        height: 100px;
        background:  green;
        position: absolute;
        left:  50px;
        top: 50px;">
  </div>
</div>

I want Firefox to get same outline effect than Chrome.

Of course i know about border or box-shadow, but i can't use border now for some other reason. Because sometimes div has radius border, in this time border or box-shadow is radius, but it should have rectangular outline, so we can't use border or box-shadow.

How can I do this?

LarAng
  • 1,255
  • 3
  • 18
  • 28
  • 1
    This is a know [FF *bug**](https://bugzilla.mozilla.org/show_bug.cgi?id=687311) reported... 7 years ago. (* Well [current specs](https://drafts.csswg.org/css-ui/#outline-props) say they let this to implementors, so is it really a bug?) – Kaiido Mar 08 '18 at 05:45
  • @Kaiido, thanks for your response, so the solution is box-shadow? – LarAng Mar 08 '18 at 06:27
  • Well if it is viable for you, then yes, you can use box-shadow as a workaround. (but with no other style than `solid`...) – Kaiido Mar 08 '18 at 06:32
  • @Kaiido, thanks, but now i can't use box-shadow, Div can take radius border property. In this case, box-shadow is radius, but i want rectangular outline. – LarAng Mar 08 '18 at 06:45

2 Answers2

0

try this add display:inline-table;

<div style="
margin: 100px;
width:  100px;
height:  100px;
background: blue;
outline: solid 1px red;
position:  relative;
display: inline-table;">
    <div style="
    width: 100px;
    height: 100px;
    background:  green;
    position: absolute;
    left:  50px;
    top: 50px;">
    </div>
Rajath Kumar PM
  • 655
  • 3
  • 9
0

try this code i replaced outline with border

<div style="
margin: 100px;
width:  100px;
height:  100px;
background: blue;
border: solid 1px red;
position:  relative;">
    <div style="
    width: 100px;
    height: 100px;
    background:  green;
    position: absolute;
    left:  50px;
    top: 50px;">
    </div>
</div>

here is the fiddle

https://jsfiddle.net/0pr1t07y/

Shaik
  • 380
  • 2
  • 15