css - Firefox outline css 属性与 Chrome 不同

标签 css google-chrome firefox outline descendant

<分区>

我正在使用 css outline 属性,我发现如果后代元素在外部,它在 Chrome 和 Firefox 之间的工作方式不同。

  • 在 Chrome 中,outline 仅适用于其自身范围,即使任何后代元素都在其范围之外。

results in chrome: blue rectangle has an outline, descendant green rectangle has not

  • 在 Firefox 中,轮廓是所有范围,包括所有后代元素。 results in Firefox: Bounding box of both blue and green has the outline

<div style="
    margin: 100px;
    width:  100px;
    height:  100px;
    background: blue;
    outline: solid 1px red;
    position:  relative;">
  <div style="
        width: 100px;
        height: 100px;
        background:  green;
        position: absolute;
        left:  50px;
        top: 50px;">
  </div>
</div>

我希望 Firefox 获得与 Chrome 相同的轮廓效果。

我当然知道边框或框阴影,但由于其他原因我现在不能使用边框。因为有时候div有radius border,此时border或者box-shadow是radius,但是应该是矩形的outline,不能用border或者box-shadow。

我该怎么做?

最佳答案

尝试添加显示:内联表;

<div style="
margin: 100px;
width:  100px;
height:  100px;
background: blue;
outline: solid 1px red;
position:  relative;
display: inline-table;">
    <div style="
    width: 100px;
    height: 100px;
    background:  green;
    position: absolute;
    left:  50px;
    top: 50px;">
    </div>

关于css - Firefox outline css 属性与 Chrome 不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49165863/

上一篇:html - 无法设置模态内部元素的tabindex

下一篇:html - 是否可以在服务器中编辑/自定义 Sass 文件并自动更新 CSS?

相关文章:

jquery - 有两个高度相同的并排 DIV,当内容的长度不断变化时,如何保持它们的内容对齐?

jquery - 需要将列表项的一部分与 li 的右侧对齐 - 使用 CSS3 Jquery column-layout

javascript - Chrome - 不播放多个视频 - 网络卡在待定状态

css - 在 Firefox 中应用类似 CSS3 效果的阴影

javascript - jQuery 图像悬停在多个动态图像之上

html - 将 flex 元素的内容对齐到底部

javascript - 带有源映射的调试器中的损坏名称

C# 如何在多个窗口中从 chrome 获取标签?

firefox - PDF.js 中的 mozdisallowselectionprint 属性有什么作用?

css - 自定义光标图像 CSS