Tags for this article: cascading style sheets, css layout, CSS Outline Styles, css tutorial, outline property
Outline property of the CSS is a confusing property. When this property is learned first, it is hard to understand how the CSS Outline property is even remotely different from border property. WWW explains that it has the following differences.
- Space is not utilized by Outlines
- Outlines can be non-rectangular as well.
Outlines don’t take up space
The above statement is confusing. Just think that how objects in the webpage cannot take the space on WebPages. The outline property does not take the space because it will always be placed on top of the element’s box.
Around an element, if an outline is placed, it does not have any kind of effect on how the elements are placed on the page. It will not change the position or size of the element. If the outline is put on the element, it will surely take the exact amount of the space, as it did not have any outline on the element. In the border’s case, this is not true. On an element, a border is added on the height and outside width of the element. Therefore, if there were 50-pixel wide along with a 2-pixel border, then it would take 54-pixels. The same image along with 2-pixel outline will take only 50-pixels width on the same page and the outline will display the images outside edge.
Outlines May or may not be Non-Rectangular
Whenever you put up the border on the element, the browser will interpret the elements as if they were one of the giant rectangular boxes. If the box is split over many lines, the browser will just leave the edges open, as the box is not closed. It is as if a browser is seeing the border along with a wide screen, which is too wide to be measured. The wide screen is wide enough for the border to be continuous rectangle.
In contrast, the edges are taken into consideration by the outline property. If the outlined element is spanned over several lines then the outline will close at the line’s end and again re-opens on the next line. If it were possible, then the outline would definitely stay fully connected and thus it creates a non-rectangular shape.
The outline property must be seen and it must be compared with the border property.
Uses of the Outline Property
Searching the items is the best use of the outline property. Most of the websites will do this using a background colour. However, the outline property can also be used and you need not worry about adding the extra spacing on the pages.
Outline colour property will accept the term ‘invert’ that will make the outline colour the inverse colour of current background. This will allow you to highlight the elements on the dynamic WebPages even without the need to know what are the colours used.
Around the active links, there would be some dotted lines and to remove them the outline property can be used.