html - 如果我悬停父级,如何触发子级?
问题描述
当悬停在父级上时,我想触发子级 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 时看到白色圆圈(在我的例子中是一张图片)。
解决方案
你的小提琴几乎是正确的。我刚刚更改了最后一个选择器,如下所示,它在父 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;
}
推荐阅读
- c# - 如何将特定文本从文本文件写入文本框?
- javascript - 将 javascript 对象数组转换为具有键和值数组的对象
- python - 如何在虚拟环境中使用 sqlite?
- python - 如何在 Python 中将纪元时间转换为我的本地时区?
- r - lm() 中汇总交互变量的解释系数
- php - Laravel 请求无法获取某些键的值
- zebra-printers - 如何从 ZPL 命令中的变量中获取一些文本
- c# - “指定类型未在目标服务器上注册。Microsoft.SqlServer.Types.SqlGeography”使用 SQLGeography 数据类型时出现异常
- javascript - 如何确保Typescript Object中的某个键值对保持在最后一个位置
- events - 如何在 AMCharts v4 CategoryAxis 的各个类别上注册事件处理程序