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

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

  1. <tfoot id='cGvFh'></tfoot>

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

    1. 专门用于 :hover 的元素覆盖 :active 的等效类

      elements specifically for :hover overriding the an equivalent class for :active(专门用于 :hover 的元素覆盖 :active 的等效类)

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

        1. <legend id='VKVHc'><style id='VKVHc'><dir id='VKVHc'><q id='VKVHc'></q></dir></style></legend>
              <bdo id='VKVHc'></bdo><ul id='VKVHc'></ul>

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

                <tbody id='VKVHc'></tbody>

              <tfoot id='VKVHc'></tfoot>
              • 本文介绍了专门用于 :hover 的元素覆盖 :active 的等效类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我的代码有一个背景,其字体颜色分配给一个类,然后有单独的类用于更改 :hover 或 :active 上的颜色,但除非我删除 :hover 特定类,否则不会触发 :active 状态.CODEPEN

                I have code to have a background with a font color assigned with one class then have separate classes for changing the color on :hover or :active but the :active state does not trigger unless I remove the :hover specific class. CODEPEN

                HTML:

                <div class="backgroundRed backgroundGreenHover backgroundBlueActive" style="width: 100px; height: 100px;"></div>
                

                CSS:

                .backgroundRed, .backgroundRedHover:hover, .backgroundRedActive:active{background:red;}
                    .backgroundGreen, .backgroundGreenHover:hover, .backgroundGreenActive:active{background:green;}
                    .backgroundBlue, .backgroundBlueHover:hover, .backgroundBlueActive:active{background:blue;}
                

                推荐答案

                :active 伪类应该在 :hover 之后,否则 :hover 覆盖(链接相关的伪类的顺序是::link | :visited | :hover | :active.).您的代码示例按预期工作,但如果您更改类 :active 伪类永远不会应用.

                :active pseudo-class should go after :hover, otherwise the :hover overwrites (The order for the link-relates pseudo-clasess is: :link | :visited | :hover | :active.). You code example works as expected but if you change the classes the :active pseudo-class never applies.

                .backgroundRed,
                .backgroundRedHover:hover,
                .backgroundRedActive:active {
                  background: red;
                }
                
                .backgroundGreen,
                .backgroundGreenHover:hover,
                .backgroundGreenActive:active {
                  background: green;
                }
                
                .backgroundBlue,
                .backgroundBlueHover:hover,
                .backgroundBlueActive:active {
                  background: blue;
                }

                <div class="backgroundRed backgroundBlueHover backgroundGreenActive" style="width: 100px; height: 100px;"></div>

                您需要更多的 CSS 行,但在 :hover 之后使用 :active 重新排序类可以正常工作.

                You need more CSS lines but reordering the classes with :active after the :hover works fine.

                .backgroundRed,
                .backgroundRedHover:hover {
                  background: red;
                }
                
                .backgroundGreen,
                .backgroundGreenHover:hover {
                  background: green;
                }
                
                .backgroundBlue,
                .backgroundBlueHover:hover {
                  background: blue;
                }
                
                .backgroundRedActive:active {
                  background: red;
                }
                
                .backgroundGreenActive:active {
                  background: green;
                }
                
                .backgroundBlueActive:active {
                  background: blue;
                }

                <div class="backgroundRed backgroundBlueHover backgroundGreenActive" style="width: 100px; height: 100px;"></div>

                这篇关于专门用于 :hover 的元素覆盖 :active 的等效类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                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 的区别?)

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

                    1. <tfoot id='rDDS2'></tfoot>
                        <tbody id='rDDS2'></tbody>
                    2. <small id='rDDS2'></small><noframes id='rDDS2'>

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