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

  • <legend id='bFN8o'><style id='bFN8o'><dir id='bFN8o'><q id='bFN8o'></q></dir></style></legend>

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

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

        是否可以根据类名在没有 Javascript 的情况下更改悬停时的多个元素外观?

        Is that possible to change multiple elements appearance on hover without Javascript, based on class name?(是否可以根据类名在没有 Javascript 的情况下更改悬停时的多个元素外观?)

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

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

                  <tbody id='dJb79'></tbody>
                • <legend id='dJb79'><style id='dJb79'><dir id='dJb79'><q id='dJb79'></q></dir></style></legend>

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

                  本文介绍了是否可以根据类名在没有 Javascript 的情况下更改悬停时的多个元素外观?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 divs 中有一个 divs 结构,类似于:

                  <div class='a'>你好</div><div class='a'>堆栈</div><div>溢出</div></div>

                  <div>你</div><div class='b'>是</div><div class='b'>最好的</div></div>

                  <div>有</div><div class='b'>一个不错的</div><div>日!!</div></div></div>

                  我希望所有具有类 adiv 在其中一个被鼠标悬停时更改背景颜色.对于所有具有类 bdiv 都相同:当悬停具有类 bdiv 之一时,所有divs with class b 应该改变背景颜色.

                  是否有可能实现此行为无需 Javascript?

                  如果答案是否定的:
                  如果知道所有具有类 adiv 都是连续的 div 是否可能在同一级别(即兄弟姐妹)?

                  如果需要,我还可以将其他类添加到 divs.

                  解决方案

                  在没有容器 <div>s 的更简单的情况下,你可以让它工作一半":

                  <div class='a'>你好</div><div class='a'>堆栈</div><div>溢出</div><div class='b'>是</div><div class='b'>最好的</div><div>有</div><div class='b'>一个不错的</div><div>日!!</div></div>

                  然后你可以使用 通用兄弟组合器, 不幸的是,它仅适用于左侧描述的元素之后的元素.因此,例如,如果您将鼠标悬停在包含The Best"的 <div> 上,那么只有那个和a nice"的 <div> 会发生变化背景:

                  div.b:hover, div.b:hover ~ div.b {背景颜色:#CCCCCC;}

                  不过,我无法想出一种仅通过 CSS 来完全处理您的场景的方法.我倾向于其他人所说的现在不可能(即使在简化的情况下).

                  I have a structure of divs inside divs, something like:

                  <div>
                      <div>
                          <div class='a'>Hello</div>
                          <div class='a'>Stack</div>
                          <div>Overflow</div>
                      </div>
                      <div>
                          <div>You</div>
                          <div class='b'>Are</div>
                          <div class='b'>The Best</div>
                      </div>
                      <div>
                          <div>Have</div>
                          <div class='b'>a nice</div>
                          <div>Day !!</div>
                      </div>
                  </div>
                  

                  I would like all divs with class a to change the background color when one of them is hovered by mouse. The same for all divs with class b: when one of divs with class b is hovered, all divs with class b should change the background color.

                  Is that possible to implement this behavior without Javascript ?

                  If the answer is no:
                  Is that possible if known that all divs with class a are consecutive divs in the same level (i.e. siblings) ?

                  I can add also other classes to divs, if needed.

                  解决方案

                  You can get it "half working" in the simpler case where there are no container <div>s:

                  <div>
                    <div class='a'>Hello</div>
                    <div class='a'>Stack</div>
                    <div>Overflow</div>
                    <div class='b'>Are</div>
                    <div class='b'>The Best</div>
                    <div>Have</div>
                    <div class='b'>a nice</div>
                    <div>Day !!</div>
                  </div>
                  

                  Then you could use the general sibling combinator, with the unfortunate caveat that it only works for elements that come after the element described on the left-hand side. So, for example, if you hovered over the <div> containing "The Best", only that and the "a nice" <div> would have a changed background:

                  div.b:hover, div.b:hover ~ div.b {
                      background-color:#CCCCCC;
                  }
                  

                  I wasn't able to come up with a way that would fully take care of your scenario through CSS alone, though. I'm leaning towards what the others have said about it not being possible (even in the simplified case) right now.

                  这篇关于是否可以根据类名在没有 Javascript 的情况下更改悬停时的多个元素外观?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
                  How do I make a TextGeometry multiline? How do I put it inside a square so it wraps like html text does inside a div?(如何制作 TextGeometry 多线?如何将它放在一个正方形内,以便它像 html 文本一样包裹在 div 内?) - IT屋-程序员软件开发技术分享社
                  Scale background image to fit ie8 window(缩放背景图像以适合 ie8 窗口)
                  @fontface in IE7 (IETEster) not working properly(IE7 (IETEster) 中的@fontface 无法正常工作)
                  Safari 5.1 breaks CSS table cell spacing(Safari 5.1 打破 CSS 表格单元格间距)
                  Put in bold part of description in metatag Drupal module(将描述的粗体部分放在元标记 Drupal 模块中)

                      • <legend id='OHaoS'><style id='OHaoS'><dir id='OHaoS'><q id='OHaoS'></q></dir></style></legend>

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

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

                            <tbody id='OHaoS'></tbody>