• <small id='YA6nV'></small><noframes id='YA6nV'>

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

    <tfoot id='YA6nV'></tfoot>

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

        使 css :hover 只影响父元素

        Make css :hover only affect parent element(使 css :hover 只影响父元素)
        <legend id='hvp70'><style id='hvp70'><dir id='hvp70'><q id='hvp70'></q></dir></style></legend>

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

            <tfoot id='hvp70'></tfoot>
            • <bdo id='hvp70'></bdo><ul id='hvp70'></ul>

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

                    <tbody id='hvp70'></tbody>
                  本文介绍了使 css :hover 只影响父元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在css中,当子事件悬停时,如何停止在父元素中触发 :hover 事件,以便仅在父元素本身悬停时触发?在这种情况下,我的子元素实际上以绝对定位定位在其父元素之外,因此当子元素悬停时父元素发生变化时,这有点奇怪.

                  In css, how can I stop the :hover event being triggered in a parent element when a child event is hovered, so that it only gets triggered when the parent itself gets hovered? In this case my child element is actually positioned outside it's parent element with absolute positioning, so it's a bit weird when the parent changes when the child gets hovered.

                  我做了一个JSFiddle来说明问题.

                  I made a JSFiddle to illustrate the problem.

                  这是我的示例所用解决方案的 JSFiddle.

                  推荐答案

                  有一个纯 css 解决方案(实际上甚至有两个),但都是有代价的.

                  There is a pure css solution (even two in fact) but both come at a cost.

                  1. 你可以添加pointer-events:none;到您的子元素 - 但它也不会响应它自己的悬停样式.Pointer-events 不幸的是,IE 11 以下版本不支持(http://caniuse.com/#search=pointer-events).

                  1. You can add pointer-events:none; to your child element - but it will not respond to it's own hover styles either. Pointer-events unfortunately are not supported in IE below version 11 (http://caniuse.com/#search=pointer-events).

                  将父元素的内容(除了定位的子元素)包装在另一个元素中(这是此方法的成本)并将悬停样式应用于此包装器.

                  Wrap content of your parent element (apart from positioned child) in another one (thats the cost of this method) and apply hover styles to this wrapper.

                  两种方法的示例这里.

                  .parent-2,
                  .parent { position:relative; background:#ddd; width:100px; height:100px; }
                  .parent:hover { background:blue; }
                  .child { position:absolute; top:0; left:130px; width:100px; height:50px; border:1px solid blue; pointer-events:none; }
                  /* doesn't work in opera and ie */
                  
                  
                  .content { position:absolute; top:0; left:0; width:100%; height:100%; z-index:0;}
                  .content:hover { background:blue; }
                  

                  这篇关于使 css :hover 只影响父元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Move link image 5px up on hover(悬停时将链接图像向上移动 5px)
                  How do I inspect CSS pseudo classes with firebug?(如何使用 firebug 检查 CSS 伪类?)
                  Why doesn#39;t CSS hover work on table rows when the cells inside the rows have class names?(当行内的单元格具有类名时,为什么 CSS 悬停在表格行上不起作用?)
                  Hover image - display div over it(悬停图像 - 在其上显示 div)
                  How to apply a CSS class on hover to dynamically generated submit buttons?(如何在悬停时将 CSS 类应用于动态生成的提交按钮?)
                  Differences between CSS3 :hover and :focus?(CSS3 :hover 和 :focus 的区别?)
                    <tbody id='GjB83'></tbody>

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

                        <tfoot id='GjB83'></tfoot>

                          • <small id='GjB83'></small><noframes id='GjB83'>