Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS "outline" different behavior behavior on Webkit & Gecko

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 a absolute position div inside another div but floating outside of it. The outline on Webkit outlines the actual parent div while on Gecko, it expands to cover the child item.

http://jsfiddle.net/KrCs4/

Am I missing anything? Is there a property that I need to overwrite on Gecko? or it should be reported as a bug?

Webkit Screenshot:

Webkit Screenshot

Firefox Screenshot:

Firefox Screenshot

EDIT:

It's confirmed to be a bug and here's a workaround: http://jsfiddle.net/7Vfee/ (You need to make sure that the parent is positioned: relative or absolute for this workaround to work.

like image 867
Elie Avatar asked May 19 '12 06:05

Elie


People also ask

What is the difference between outline and border in CSS?

Note: Outline differs from borders! Unlike border, the outline is drawn outside the element's border, and may overlap other content. Also, the outline is NOT a part of the element's dimensions; the element's total width and height is not affected by the width of the outline.

What is CSS outline properties?

The CSS outline property defines the width, line style, and color of the outline of an element. It is a shorthand property for setting the outline-width, outline-style, and outline-color CSS properties.

What is outline offset in CSS?

The outline-offset CSS property sets the amount of space between an outline and the edge or border of an element.


2 Answers

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; 
like image 63
Rumpleteaser Avatar answered Sep 30 '22 12:09

Rumpleteaser


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.

like image 33
BoltClock Avatar answered Sep 30 '22 14:09

BoltClock