【问题标题】:Firefox CSS outline bug?Firefox CSS 大纲错误?
【发布时间】:2015-03-16 14:13:39
【问题描述】:

在 Chrome 和 IE9 上,我指定的 CSS 轮廓完全符合我的要求,并充当我正在设计样式的元素周围的第二个边框。

但在 Firefox 上,轮廓会向外扩展,以便包含我生成的 ::after 伪元素以及主要元素。

这是一个错误,还是预期的?有什么好的/简单/干净的解决方法吗?如果可能的话,我宁愿避免添加额外的标记。

【问题讨论】:

  • 发布您的代码....
  • Normalize.css 使浏览器渲染所有元素更加一致并符合现代标准。它仅针对需要规范化的样式。 - necolas.github.io/normalize.css
  • 不是我自己的代码,但这里有一个例子。 codepen.io/romainberger/pen/nuxlh 从轮廓切换到框阴影有效,但我仍然很好奇轮廓是否可以以某种方式正确使用。有没有我遗漏的不起眼的财产,诸如此类。
  • 添加 normalize.css 对 Luis 没有任何影响。
  • 如果这是我认为的错误,它应该在几个月前修复。您是否在旧版本的 Firefox 上进行测试?

标签: css firefox outline


【解决方案1】:

是的,它看起来像 Firefox 中的一个错误(排序),请查看 here。现在有些人似乎在争论,如果孩子是绝对的,或者说大纲是否应该涵盖“一切”,这有点奇怪,而且在使用 position: absolute 时完全不是预期的行为,在至少对我来说。

解决方案 1:

  • 使用额外的伪选择器为.main 类工作(我看到你没有使用:before 类,所以你可以使用它),然后从那里开始工作,似乎工作正常全面的。
  • 查看 demo here 或下面的 sn-p

.main {
  position: relative;
  width: 100px;
  height: 100px;
  margin: 10px auto;
  border: 2px solid #f00;
}
.main:before {
  content: '';
  position: absolute;
  border: 2px solid #00f;
  /*adjust if needed if using border-box*/
  top: -4px;
  right: -4px;
  bottom: -4px;
  left: -4px;
  z-index: -1;
}
.main:after {
  content: 'Hello';
  position: absolute;
  width: 100px;
  text-align: center;
  bottom: -50px;
}
.wtf {
  width: 400px;
  margin: 90px auto;
}
<div class="main"></div>
<div class="wtf">
  <p>In Chrome and Safari the 'Hello' is outside of the outline.</p>
  <p>In firefox the outline is extended and the 'Hello' is inside the outline. Bug from Firefox or is there a way to fix this?</p>
</div>

解决方案 2:

  • 使用 box-shadow 道具。无需额外的 :pseudo 选择器即可实现该效果
  • 查看 demo here 或下面的 sn-p

.main {
  position: relative;
  width: 100px;
  height: 100px;
  margin: 10px auto;
  border: 2px solid #f00;
  box-shadow: 0 0 0 2px #00f;
}
.main:after {
  content: 'Hello';
  position: absolute;
  width: 100px;
  text-align: center;
  bottom: -50px;
}
.wtf {
  width: 400px;
  margin: 90px auto;
}
<div class="main"></div>
<div class="wtf">
  <p>In Chrome and Safari the 'Hello' is outside of the outline.</p>
  <p>In firefox the outline is extended and the 'Hello' is inside the outline. Bug from Firefox or is there a way to fix this?</p>
</div>

【讨论】:

  • 您好,这看起来不错的解决方案。但是如果 main 的边框宽度改变了, :after 的边框或 box-shadow 的位置就会改变。我们如何解决这个问题?谢谢
猜你喜欢
  • 2012-10-22
  • 2011-12-11
  • 1970-01-01
  • 2012-11-03
  • 2018-08-16
  • 2013-10-26
  • 1970-01-01
  • 2013-06-25
  • 2012-09-08
相关资源
最近更新 更多