javascript - 某些网站不尊重顶部和左侧定位

标签 javascript html css

我正在创建一个扩展以覆盖在页面上并创建一个透明层以仅显示页面上的某些元素。类似于这里的东西 - In this link

首先,对于叠加层,我创建了一个 div overlay,其中包含 position: fixed background: transparentpointer-events: nonez-index: 9999 所以这是最顶层。然后我创建了另一个 div(“shadow”),它根据目标元素的 getBoundingClientRect() 使用 box-shadow 来透视顶部和左侧。

我遇到一个问题,“影子”div 不遵守某些网站上的顶部和左侧定位。我需要为其中一些添加 margin-top 和 margin-left 。这是为什么?

.overlay {
  position: fixed;
  top: 0px;
  left: 0px;
  width: 100%;
  height: 100%;
  z-index: 9999;
  pointer-events: none;
  background-color: transparent;
}

.shadow {
  top: 3935px;
  left: 1008px;
  width: 26.7344px;
  height: 15px;
  border-radius: 100%;
  box-shadow: rgba(184, 20, 129, 0.6) 0px 0px 0px 141.421vmax;
}
<div id="overlay" class="overlay">
  <div id="shadow" class="shadow">
  </div>
</div>

最佳答案

.shadow div 没有position 样式,这意味着它可能默认为position: static。当元素使用 position: static 时,topleft 等不适用。

来自 MDN :

When position is set to static, the top property has no effect.

因此,我完全不确定您是如何让它在任何网站上运行的。在您提供的示例中,带有 box-shadow 的元素也有 position: absolute

关于javascript - 某些网站不尊重顶部和左侧定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50429138/

相关文章:

javascript - 基于字符出现的 CSS 选择器?

javascript - 如何重构瀑布.then()

javascript - 合并多个 div,然后撤消合并

javascript - 辅助功能 - Android Talkback 不会在 HTML 内容上触发焦点事件

javascript - Angular 与静态页面或组件? (成分太多?)

javascript - 从左侧菜单滑动

css - 在 `li` 元素中居中对齐 anchor ?

javascript - 当 html 文件中遇到 &lt;script&gt; 标签时会发生什么?

firefox - 如何使用 JavaScript 清除应用程序缓存(HTML5 功能)?

css - 无法在 'CSSStyleDeclaration' 上设置索引属性 : Index property setter is not supported