【发布时间】:2016-02-26 21:05:33
【问题描述】:
给定 div 和 tabindex="0" 我在 Firefox 和 Chrome 上得到了这种奇怪的 outline 行为。
.inner {
margin-left: -20px;
padding-left: 20px;
}
.context {
margin-left: 40px;
background-origin: content-box;
background-color: limegreen;
}
.custom_outline:focus {outline: 3px solid blue;}
<div class="context" tabindex="0">
<h1>Wrong outline on Firefox</h1>
<h2>... but on Chrome is even WORSE</h2>
<div>
<div class="inner">Foo</div><div class="inner">Bar</div>
</div>
</div>
<div class="context custom_outline" tabindex="0">
<h1>Wrong outline on Firefox</h1>
<h2>... but on Chrome is BETTER if I set an explicit outline</h2>
<div>
<div class="inner">Foo</div><div class="inner">Bar</div>
</div>
</div>
默认情况下:
设置明确的大纲:
为什么会出现这种不一致的行为?是什么触发了 Chrome 的差异?谁更尊重 W3C 规范?
我想要实现的结果是 Chrome 的最后一种情况,轮廓包裹div 并忽略负边距(仅考虑 border-box ,就像 background-origin 属性发生的那样)
我该怎么做?
【问题讨论】:
标签: css google-chrome cross-browser outline