将鼠标悬停在父级上时,我想触发子级div。搜索了多个主题,但没有发现实际的帮助,除了:class.parent:hover class.child {}
我的主题在以下方面没有重复:Css hover child to trigger effect on parent
提供的来源:https://jsfiddle.net/Arty_Prof/81e4uy3w/
html {
background: black;
}
#buttonStart {
position: absolute;
width: 15%;
height: 10%;
bottom: 15%;
left: 5%;
}
#imageStart {
width: 100%;
height: 100%;
}
#buttonStart:hover .hovicon.effect-3.sub-b {
cursor: pointer;
}
.hovicon {
display: inline-block;
font-size: 45px;
line-height: 90px;
cursor: pointer;
width: 90px;
height: 90px;
border-radius: 50%;
text-align: center;
position: relative;
text-decoration: none;
z-index: 1;
color: #fff;
}
.hovicon.auto-width {
width: auto;
height: auto;
}
.hovicon:after {
pointer-events: none;
position: absolute;
width: 100%;
height: 100%;
border-radius: 50%;
content:'';
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
}
.hovicon:before {
speak: none;
font-size: 48px;
line-height: 90px;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
display: block;
-webkit-font-smoothing: antialiased;
}
.hovicon.effect-3 {
position: absolute;
bottom:-13%;
left: 62%;
font-size: 3.8em;
-webkit-transition: color 0.3s;
-moz-transition: color 0.3s;
transition: color 0.3s;
}
.hovicon.effect-3:after {
top: -2px;
left: -2px;
padding: 2px;
z-index: -1;
background: #fff;
-webkit-transition: -webkit-transform 0.2s, opacity 0.3s;
-moz-transition: -moz-transform 0.2s, opacity 0.3s;
transition: transform 0.2s, opacity 0.3s;
}
/* Effect 3b */
.hovicon.effect-3.sub-b, .hovicon.effect-3.sub-b i {
color: #fff;
}
.hovicon.effect-3.sub-b:hover, .hovicon.effect-3.sub-b:hover i {
color: #696969;
}
.hovicon.effect-3.sub-b:after {
-webkit-transform: scale(1.3);
-moz-transform: scale(1.3);
-ms-transform: scale(1.3);
transform: scale(1.3);
opacity: 0;
}
.hovicon.effect-3.sub-b:hover:after {
-webkit-transform: scale(1);
-moz-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
opacity: 1;
}
<div id="buttonStart">
<div><input type="image" id="imageStart" src="https://cdn.pixabay.com/photo/2017/10/10/07/48/beach-2836300_960_720.jpg">
<div class="hovicon effect-3 sub-b" id="buttonStartEffect">   </div>
</div>
</div>
小提琴中的其他代码。
我希望将鼠标悬停在父div(我的情况下为图片)上时会看到白色圆圈。
答案 0 :(得分:0)
您的小提琴几乎是正确的。我只是改变了最后一个选择器,如下所示,它在父div的悬停上显示了圆形动画。请在CSS下方尝试
html {
background: black;
}
#buttonStart {
position: absolute;
width: 15%;
height: 10%;
bottom: 15%;
left: 5%;
}
#imageStart {
width: 100%;
height: 100%;
}
#buttonStart:hover .hovicon.effect-3.sub-b {
cursor: pointer;
}
/* Effect 3 */
.hovicon {
display: inline-block;
font-size: 45px;
line-height: 90px;
cursor: pointer;
width: 90px;
height: 90px;
border-radius: 50%;
text-align: center;
position: relative;
text-decoration: none;
z-index: 1;
color: #fff;
}
.hovicon.auto-width {
width: auto;
height: auto;
}
.hovicon:after {
pointer-events: none;
position: absolute;
width: 100%;
height: 100%;
border-radius: 50%;
content: '';
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
}
.hovicon:before {
speak: none;
font-size: 48px;
line-height: 90px;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
display: block;
-webkit-font-smoothing: antialiased;
}
.hovicon.effect-3 {
position: absolute;
bottom: -13%;
left: 62%;
font-size: 3.8em;
-webkit-transition: color 0.3s;
-moz-transition: color 0.3s;
transition: color 0.3s;
}
.hovicon.effect-3:after {
top: -2px;
left: -2px;
padding: 2px;
z-index: -1;
background: #fff;
-webkit-transition: -webkit-transform 0.2s, opacity 0.3s;
-moz-transition: -moz-transform 0.2s, opacity 0.3s;
transition: transform 0.2s, opacity 0.3s;
}
/* Effect 3b */
.hovicon.effect-3.sub-b,
.hovicon.effect-3.sub-b i {
color: #fff;
}
.hovicon.effect-3.sub-b:hover,
.hovicon.effect-3.sub-b:hover i {
color: #696969;
}
.hovicon.effect-3.sub-b:after {
-webkit-transform: scale(1.3);
-moz-transform: scale(1.3);
-ms-transform: scale(1.3);
transform: scale(1.3);
opacity: 0;
}
#buttonStart:hover .hovicon.effect-3.sub-b:after {
-webkit-transform: scale(1);
-moz-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
opacity: 1;
}