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

    <legend id='50GPg'><style id='50GPg'><dir id='50GPg'><q id='50GPg'></q></dir></style></legend>

      <small id='50GPg'></small><noframes id='50GPg'>

        <bdo id='50GPg'></bdo><ul id='50GPg'></ul>
      <tfoot id='50GPg'></tfoot>
    1. 使用 :hover 修改另一个类的css?

      时间:2023-11-01
        <tbody id='HOD0i'></tbody>

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

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

              • <tfoot id='HOD0i'></tfoot>
              • 本文介绍了使用 :hover 修改另一个类的css?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                当只使用 css 将鼠标悬停在另一个类的元素上时,有没有办法修改一个类的 css ?

                Is there a way to modify the css for one class when hovering on an element from another class using only css ?

                类似:

                .item:hover .wrapper { /*some css*/ }
                

                只有 'wrapper' 不在 'item' 内,它在其他地方.

                Only 'wrapper' is not inside 'item', it's somewhere else.

                我真的不想在这么简单的事情上使用 javascript,但如果我必须这样做,我该怎么做?这是我失败的尝试:

                I really don't want to use javascript for something this simple, but if I have to, how would I do it ? Here's my failed attempt:

                document.getElementsByClassName('item')[0].onmouseover="document.getElementsByClassName('wrapper')[0].style.background="url('some url')";";
                

                每个类只有一个元素.不知道为什么他们在制作模板时不使用 ID,但就是这样,我无法更改.

                There's only one element of each class. Don't know why they didn't use IDs when they made the template, but that's just how it is and I can't change it.

                这是一个菜单.每个菜单元素都有一个不同的类.当您将鼠标悬停在元素上时,右侧会弹出一个子菜单.这就像一个叠加层,当我使用检查元素"工具时,我可以看到当子菜单处于活动状态时整个网站的 html 都发生了变化(这意味着除了子菜单什么都没有).我称之为包装器"的类具有控制子菜单背景的 css.我真的看不出这两个类之间有什么联系.

                It's a menu. Each menu element has a distinct class. When you hover on the element a submenu pops up to the right. It's like an overlay, when I use the 'Inspect Element' tool I can see that the whole website html changes when the submenu is active(meaning there's nothing but the submenu). The class I call 'wrapper' has the css that controls the background for the submenu. There's really no connection that I can see between the two classes.

                推荐答案

                目前在 CSS 中是不可能的,除非你想选择一个子元素或兄弟元素(微不足道,在此处的其他答案中有描述).

                It's not possible in CSS at the moment, unless you want to select a child or sibling element (trivial and described in other answers here).

                对于所有其他情况,您将需要 JavaScript.jQuery 和 Angular 等框架可以相对轻松地解决这个问题.

                For all other cases you'll need JavaScript. jQuery and frameworks like Angular can tackle this problem with relative ease.

                使用新的 CSS (4) 选择器 :has(),您可以将能够定位父元素/类,在不久的将来使纯 CSS 解决方案可行!

                With the new CSS (4) selector :has(), you'll be able to target parent elements/classes, making a CSS-Only solution viable in the near future!

                这篇关于使用 :hover 修改另一个类的css?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:悬停时旋转或旋转图像 下一篇:是否可以在悬停时仅更改 rgba 背景颜色的 alpha?

                相关文章

                <tfoot id='D6xHp'></tfoot>
              • <legend id='D6xHp'><style id='D6xHp'><dir id='D6xHp'><q id='D6xHp'></q></dir></style></legend>

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

                    • <bdo id='D6xHp'></bdo><ul id='D6xHp'></ul>
                  1. <small id='D6xHp'></small><noframes id='D6xHp'>