admin管理员组文章数量:1410674
I created a simple chrome extension tool to show small text message (a div with z-index 999999) on the page a user will be browsing. Sometimes, the div still appears below the existing page's elements and worse, the contents of the div changes because the page already has it's own CSS rules.
The challenge is how to ensure that my text message will appear on top of all elements (works on any site) and that it will look consistent and unaffected by existing CSS rules.
Would iframe solve this issue? But still, even with an iframe, it still needs to appear on top of all elements and seems like z-index doesn't work always.
I created a simple chrome extension tool to show small text message (a div with z-index 999999) on the page a user will be browsing. Sometimes, the div still appears below the existing page's elements and worse, the contents of the div changes because the page already has it's own CSS rules.
The challenge is how to ensure that my text message will appear on top of all elements (works on any site) and that it will look consistent and unaffected by existing CSS rules.
Would iframe solve this issue? But still, even with an iframe, it still needs to appear on top of all elements and seems like z-index doesn't work always.
Share Improve this question asked Aug 24, 2014 at 21:34 user299709user299709 5,42212 gold badges59 silver badges90 bronze badges 2-
1
Does the element have
position:absolute
? – Kiee Commented Aug 24, 2014 at 21:35 - Note, the max z-index is usually 2147483647 (source) – GitaarLAB Commented Aug 24, 2014 at 21:41
1 Answer
Reset to default 7If you want to overlap anything with any element, use z-index
. You must consider:
You must use the highest
z-index
value you can, in order to position the element above other elements in the same stacking context.
See Minimum and Maximum value of Z-INDEX.To make
z-index
work, the element must be positioned.
For example,position: relative
orposition: absolute
.A huge
z-index
will be useless if its stacking context is below other elements. To avoid this situation:- Reduce as much as you can the number of ancestors of your element, which potentially could be stacking contexts.
- Make sure they aren't stacking contexts. They will need
z-index: auto
opacity: 1
- On some browsers,
position
shouldn't befixed
will-change
shouldn't be any of the properties above
If there is flash, you won't be able to overlap it whatever the
z-index
unless you modify itswmode
attribute totransparent
oropaque
.
Note this change will hurt the performance of that applet.
Alternatively, HTML5 introduces <dialog>
element, which has showModal
method. Thad method, when called, pushes the dialog to document's pending dialog stack, which means that it will be added to the top layer layer.
本文标签: htmljavascript ensure element always appears on topStack Overflow
版权声明:本文标题:html - javascript: ensure element always appears on top - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744988955a2636263.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论