【问题标题】:Hovering child triggers hover for parent? [duplicate]悬停的孩子触发父母的悬停? [复制]
【发布时间】:2017-01-25 15:10:39
【问题描述】:

我有一个父元素(在这种情况下是一个按钮),而这个父按钮有五个子按钮。这是这个的html

<div id="C_Btn3" class="AtlasRootButton multiButton1 AtlasCircleButton" style="height: 3rem; width: 3rem; line-height: 3rem;">
    <div class="fa fa-gamepad fa-3x"></div>
    <div class="AtlasButton subButton AtlasCircleButton" style="position: relative; height: 3rem; width: 3rem; line-height: 3rem; display: inline-block; bottom: 8rem; left: -7rem;"></div>
    <div class="AtlasButton subButton AtlasCircleButton" style="position: relative; height: 3rem; width: 3rem; line-height: 3rem; display: inline-block; bottom: 15.5rem; left: -1rem;"></div>
    <div class="AtlasButton subButton AtlasCircleButton" style="position: relative; height: 3rem; width: 3rem; line-height: 3rem; display: inline-block; bottom: 17rem; left: 4.75rem;"></div>
    <div class="AtlasButton subButton AtlasCircleButton" style="position: relative; height: 3rem; width: 3rem; line-height: 3rem; display: inline-block; bottom: 13.25rem; left: 4rem;"></div>
    <div class="AtlasButton subButton AtlasCircleButton" style="position: relative; height: 3rem; width: 3rem; line-height: 3rem; display: inline-block; bottom: 17.75rem; left: -5rem;"></div>
</div>

这里是相关的css

.AtlasCircleButton {
    padding: 0.75rem;
    border-radius: 50%;
    text-align: center;
    vertical-align: middle;
}

.AtlasMultiCircleButton {
    min-width: 1rem;
    min-height: 1rem;
    display: inline-block;
    padding: 5px;
    color: white;
    background-color: black;
    cursor: pointer;
}

.AtlasButton {
    display: inline-block;
    padding: 5px;
    color: white;
    background-color: black;
    cursor: pointer;
    transition: 0.3s;
}

.AtlasButton:hover {
    color: black;
    background-color: lightgrey;
    transition: 0.3s;
}

.AtlasRootButton {
    display: inline-block;
    padding: 5px;
    color: white;
    background-color: black;
    cursor: pointer;
    transition: 0.3s;
}

.AtlasRootButton:hover {
    color: black;
    background-color: lightgrey;
    transition: 0.3s;
}

.multiButton1 {
    background-color: red;
    color: white;
}

.multiButton1:hover {
    background-color: blue;
    color: white;
}

.subButton {
    z-index: 99;
}

我一生无法弄清楚的问题是,当我将鼠标悬停在其中一个孩子上时,它也会触发父母的悬停,这不是我想要的!我猜这是在css中的某个地方,但我无法从谷歌搜索这个主题中找到任何东西,只有关于让孩子的悬停试图触发父母的悬停样式的事情,这与我想要的完全相反。

编辑

我为根按钮赋予了自己独特的类,但同样的问题仍然存在。我发现的一件事是,当我通过单击悬停复选框触发 chrome 开发工具中子按钮的悬停时,根按钮悬停不会被触发,但在正常执行时不会触发。

【问题讨论】:

  • 我是.AtlasButton:hover
  • 是的,你给了你的按钮持有者和你的按钮一样的类
  • 您标记为正确的答案是不正确的。这与切换课程无关,而是每次您希望悬停它的孩子时,您都在悬停父级。您可以从父级中取出子按钮或评论父级:悬停行为,因此当悬停它的子级时,它没有链接。
  • 我进行了建议的编辑,但问题仍然存在。见上面的编辑

标签: html css


【解决方案1】:

因为您的父 div 类和子 div 类是相同的。两者都是 atlasbutton。当您将鼠标悬停在元素上时,例如在您的情况下将 atlasbutton:hover 更改为 subbutton:hover

注意:对不起,我的英语不好。

【讨论】:

  • 这样做并没有改变结果
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-01-16
  • 2018-07-28
  • 1970-01-01
  • 2022-12-26
  • 2014-08-26
  • 2012-08-14
  • 1970-01-01
相关资源
最近更新 更多