css - 位置为 : fixed not working in tag <button> in Firefox 的伪元素

标签 css firefox button css-position

我有一个问题。在 Firefox 中 - 带有 position: fixed in tag button 的伪元素不覆盖该按钮。

例子

<button class='test'>lalal</button>

.test {
    position: relative;
}
.test::after {
    content: '';
    position: fixed;
    cursor: pointer;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    background-color: rgba(0,0,0,0.5);
    z-index: 1;
}

https://jsfiddle.net/xt9eLb8z/4/

最佳答案

不要使用 position:fixed 使用 position:absolute

使用 position:fixed 时,元素与 viewport 而不是父元素相关并根据其大小。

The element is removed from the normal document flow, and no space is created for the element in the page layout. It is positioned relative to the initial containing block established by the viewport, except when one of its ancestors has a transform, perspective, or filter property set to something other than none (see the CSS Transforms Spec), in which case that ancestor behaves as the containing block. (Note that there are browser inconsistencies with perspective and filter contributing to containing block formation.) Its final position is determined by the values of top, right, bottom, and left.

MDN

.test::after {
  content: '';
  position: absolute;
  cursor: pointer;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1;
}

.test {
  position: relative;
}
<button class='test'>lalal</button>

关于css - 位置为 : fixed not working in tag <button> in Firefox 的伪元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50964703/

相关文章:

javascript - Firefox 什么时候创建一个新的内部窗口

firefox - mozilla 存储库中 firefox 版本的标签是什么?

android - View 底部带有按钮的 Webview

css - 如何使 ng-show/ng-hide 过渡动画更流畅

javascript - 我可以在我的 css 文件中使用通过 Javascript 获取的变量值吗?

html - 正确的表格对齐方式和行跨度

c# - 为 Winform 创建复选框

css - jquery mobile listview 在图像后换行

html - 如何在 Firefox 中使用 CSS 为用户选择的选项着色

html - jQuery 数据表中的纯 HTML 导出按钮