开发者

Why is there a need to add outline to CSS? Is outline redundant to the existing ones?

Today I notice outline propery in CSS. However I don't know why it is added to CSS? What for?开发者_JS百科 For me, margin, padding, border is enough.


outline creates a border outside the element's area, not adding to its width and not influencing the surrounding layout. From the quirksmode.org page on outline:

The outline is not actually a part of the box, it does not count in any way towards the width or height of a box.

That is a very useful feature indeed, because it allows e.g. highlighting an element on hover / focus actions without disturbing the neighboring elements. The slight dotted outline around focused links in Firefox is done using the outline property.

It's not supported by IE < 8, though, so it's only of limited everyday use.

  • Quirksmode.org compatibility table


A quick google, http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=outline+css, leads to this article which mentions that you can kill the dotted borders on anchors and such with outline.

To add, it's a border that doesn't take up space of the element and doesn't shift things around. Can be useful for debugging. Also not supported in IE6/IE7.


For this reason :)

Notice the dotted border around the image:

Why is there a need to add outline to CSS? Is outline redundant to the existing ones?

It is used to remove that.


It's usually used to indicate focus from what I understand. If you look at some people's CSS resets, they will do something like this:

*:focus { outline: none; }

You'll see it mostly around anchor tags if you just open up a page and starting pressing TAB a bunch of times you should see different links have the outline applied unless the stylesheet specifically says not to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜