• <tfoot id='ebK3L'></tfoot>

    <i id='ebK3L'><tr id='ebK3L'><dt id='ebK3L'><q id='ebK3L'><span id='ebK3L'><b id='ebK3L'><form id='ebK3L'><ins id='ebK3L'></ins><ul id='ebK3L'></ul><sub id='ebK3L'></sub></form><legend id='ebK3L'></legend><bdo id='ebK3L'><pre id='ebK3L'><center id='ebK3L'></center></pre></bdo></b><th id='ebK3L'></th></span></q></dt></tr></i><div id='ebK3L'><tfoot id='ebK3L'></tfoot><dl id='ebK3L'><fieldset id='ebK3L'></fieldset></dl></div>

        <bdo id='ebK3L'></bdo><ul id='ebK3L'></ul>

      1. <legend id='ebK3L'><style id='ebK3L'><dir id='ebK3L'><q id='ebK3L'></q></dir></style></legend>

        <small id='ebK3L'></small><noframes id='ebK3L'>

      2. 为什么负 z-index 会消除非静态定位元素的悬停功能?

        时间:2023-11-30
            <tbody id='9FTe9'></tbody>

            <bdo id='9FTe9'></bdo><ul id='9FTe9'></ul>
            <tfoot id='9FTe9'></tfoot>

                  <legend id='9FTe9'><style id='9FTe9'><dir id='9FTe9'><q id='9FTe9'></q></dir></style></legend>
                • <small id='9FTe9'></small><noframes id='9FTe9'>

                  <i id='9FTe9'><tr id='9FTe9'><dt id='9FTe9'><q id='9FTe9'><span id='9FTe9'><b id='9FTe9'><form id='9FTe9'><ins id='9FTe9'></ins><ul id='9FTe9'></ul><sub id='9FTe9'></sub></form><legend id='9FTe9'></legend><bdo id='9FTe9'><pre id='9FTe9'><center id='9FTe9'></center></pre></bdo></b><th id='9FTe9'></th></span></q></dt></tr></i><div id='9FTe9'><tfoot id='9FTe9'></tfoot><dl id='9FTe9'><fieldset id='9FTe9'></fieldset></dl></div>
                  本文介绍了为什么负 z-index 会消除非静态定位元素的悬停功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I just noticed that setting z-index:-1 to non-statically positioned elements removes their hovering capabilities. Surprisingly the hovering capabilities of absolutely and fixed positioned elements varie with conditions,

                  • Absolutely/Fixed positioned elements loose the hovering capability partially only if there is some text written after them. Hovering over near the top border doesn't work. If there is nothing after them then hovering works properly.

                  • Relatively positioned elements loose the hovering capability completely even if there is no text after them.

                  Relatively positioned:

                  <!DOCTYPE html>
                  <html>
                  <style>
                  .tooltip {
                      position: relative;
                      display: block; 
                      border: 5px solid black;
                      padding: 5px;
                      z-index: -1;
                  }
                  
                  .tooltip:hover {
                      color:red; background-color: yellow;
                  }
                  </style>
                  <body style="text-align:center;">
                  
                  <p>Move the mouse over the text below:</p>
                  
                  <div class="tooltip">
                  Hover over me
                  </div>
                  
                  
                  
                  </body>
                  </html>

                  Absolutely positioned with text after it:

                  <!DOCTYPE html>
                  <html>
                  <style>
                  .tooltip {
                      position: absolute;
                      display: block; 
                      border: 5px solid black;
                      padding: 5px;
                      z-index: -1;
                  }
                  
                  .tooltip:hover {
                      color:red; background-color: yellow;
                  }
                  </style>
                  <body style="text-align:center;">
                  
                  <p>Move the mouse over the text below:</p>
                  
                  <div class="tooltip">
                  Hover over me
                  </div>
                  
                  RAndom text
                  
                  </body>
                  </html>

                  Fixed positioned with text after it:

                  <!DOCTYPE html>
                  <html>
                  <style>
                  .tooltip {
                      position: fixed;
                      display: block; 
                      border: 5px solid black;
                      padding: 5px;
                      z-index: -1;
                  }
                  
                  .tooltip:hover {
                      color:red; background-color: yellow;
                  }
                  </style>
                  <body style="text-align:center;">
                  
                  <p>Move the mouse over the text below:</p>
                  
                  <div class="tooltip">
                  Hover over me
                  </div>
                  
                  RAndom text
                  
                  </body>
                  </html>

                  Question: Why does setting z-index:-1 remove the hovering capabilities of absolutely/fixed positioned elements, partially if there is text after them, and relative positioned elements completely?


                  Addendum: From the help of other users I've understood the concept. But there all still some doubts left:

                  • Why does the whole viewport get the color of the body? The border shows that body is not all over the view port but if we give the body some color then the whole view port gets that color.

                  • If we hover over the inner child box, having z-index:-1, then the parent container(i.e. body) is automatically hovered. Why?

                  解决方案

                  You may know how z-index works?

                  1. When you use positive z-index, the element is moved to the up layer.

                  2. When you use negative z-index, the element is moved to the down layer.

                  Now, lets look at the following pictures:

                  In the preceding picture, the flow of the document is normal. As the element div is positioned relatively the height of the wrapper element is increased automatically. And the z-index is set to 1 layer up to the wrapper element. We can hover over the element as it is above the wrapper.

                  In the preceding picture, the z-index of the element is set to -1 which means the element layer is 1 layer down to the wrapper element. And the covering wrapper element is above the element by which we cannot hover over that element.

                  In the preceding picture, the flow of the document is not normal, so called out of flow. As the div element is positioned fixed or absolutely the height of the wrapper element is not increased. And the z-index is set to 1 layer up to the wrapper element and we can hover over the element.

                  In the preceding picture, the z-index of the element is set to -1 which means the element layer is 1 layer down to the wrapper element. And the covering wrapper element is above the element but still the element is not covered by the wrapper as its height is not increased up to the layer that's why we can still hover over the element that is positioned fixed or absolutely.

                  Hope! This makes clear up things to you about z-index.

                  这篇关于为什么负 z-index 会消除非静态定位元素的悬停功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:答:悬停不工作 下一篇:(CSS) 如何在 &lt;img&gt; 上定位文本(带背景颜色)没有绝对定位的标签

                  相关文章

                  <i id='iRanJ'><tr id='iRanJ'><dt id='iRanJ'><q id='iRanJ'><span id='iRanJ'><b id='iRanJ'><form id='iRanJ'><ins id='iRanJ'></ins><ul id='iRanJ'></ul><sub id='iRanJ'></sub></form><legend id='iRanJ'></legend><bdo id='iRanJ'><pre id='iRanJ'><center id='iRanJ'></center></pre></bdo></b><th id='iRanJ'></th></span></q></dt></tr></i><div id='iRanJ'><tfoot id='iRanJ'></tfoot><dl id='iRanJ'><fieldset id='iRanJ'></fieldset></dl></div>

                  <legend id='iRanJ'><style id='iRanJ'><dir id='iRanJ'><q id='iRanJ'></q></dir></style></legend>

                • <tfoot id='iRanJ'></tfoot>

                  1. <small id='iRanJ'></small><noframes id='iRanJ'>

                    • <bdo id='iRanJ'></bdo><ul id='iRanJ'></ul>