CSS中边框和轮廓属性的区别是什么?
如果没有区别,为什么同一事物有两种性质?
CSS中边框和轮廓属性的区别是什么?
如果没有区别,为什么同一事物有两种性质?
当前回答
tldr;
W3C将其解释为以下区别:
大纲不占用空间。 轮廓可以是非矩形的。
源
大纲应用于可访问性
还应该注意到大纲的主要目的是可访问性。将其设定为大纲:应该避免任何内容。
如果你必须删除它,它可能是一个更好的主意提供替代样式:
我看过很多关于如何使用outline:none或outline:0删除焦点指示器的技巧。请不要这样做,除非您将大纲替换为其他内容,以便于查看哪个元素具有键盘焦点。移除键盘焦点的视觉指示器会让那些依赖键盘导航的人在导航和使用你的网站时变得非常困难。
来源:“不要从链接和窗体控件中删除轮廓”,365 Berea Street
更多的资源
http://outlinenone.com/
其他回答
作为一个使用“outline”的实际示例,系统后面模糊的虚线边界集中在一个网页上(例如。可以使用outline属性来控制(至少,我知道它可以在Firefox中,没有尝试过其他浏览器)。
一种常见的“图像替换”技术是使用,例如:
<div id="logo"><a href="/">Foo Widgets Ltd.</a></div>
在CSS中:
#logo
{
background: url(/images/logo.png) center center no-repeat;
}
#logo a
{
display: block;
text-indent: -1000em;
}
问题是当焦点到达标签时,轮廓会向左偏移1000em。Outline可以让您关闭这些元素的焦点轮廓。
我相信IE开发者工具栏在“选择”模式下突出显示要检查的元素时,也使用了一些类似“隐藏”的东西。这很好地说明了“提纲”不占空间的事实。
think about outline as a border that a projector draw outside something as a border is an actual object around that thing. a projection can easily overlap but border don't let you pass. some times when i use grid+%width, border will change the scaling on view port,for example a div with width:100% in a parent with width:100px fills the parent completely, but when i add border:solid 5px to div it make the div smaller to make space for border(although it's rare and work-aroundable!) but with outline it doesn't have this problem as outline is more virtual :D it's just a line outside the element but the problem is if you don't do spacing properly it would overlap with other contents.
简而言之: 优点:轮廓 它不会打乱间距和位置 缺点: 重叠几率高
我做了一小段css/html代码,只是为了看看两者之间的区别。
Outline最好包含可能溢出的子元素,特别是在内联容器中。
Border更适合于块行为元素。
为您演奏,先生!
来自:http://webdesign.about.com/od/advancedcss/a/outline_style.htm
CSS outline属性是一个令人困惑的属性。当你第一次了解它时,你很难理解它与边境财产有什么不同。W3C将其解释为以下区别: 大纲不占用空间。 轮廓可以是非矩形的。
Border是在元素内部创建的,而outline是在元素外部创建的。因此,border与元素的宽度和高度一起计算,而outline绘制在元素外部。