<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 的等效类

      时间:2023-11-30

          <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 的等效类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇::active 与 :hover 不同时的样式按钮 下一篇:CSS/JQuery 悬停只影响悬停元素而不影响父元素

                相关文章

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

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

                  <legend id='rDDS2'><style id='rDDS2'><dir id='rDDS2'><q id='rDDS2'></q></dir></style></legend>
                  1. <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>