我想让我的伪元素的边框在其父元素的父元素悬停时移动。基本上我希望它在我将鼠标悬停在 “lk” 上时移动,而不是仅在将鼠标悬停在 “ci” 上时激活,但我似乎无法让它工作.它只适用于 div 吗?如果是这样,我愿意接受这个选项。我已经尝试过使用 div 进行类似的尝试,但我似乎仍然无法让它工作,所以我很高兴学习如何做。
HTML
<lk><de>Name:</de><ci>Luci`a Bloom</ci></lk>
CSS
lk{
margin-right:49px;
}
de{
color:black;
font-family:karla;
font-weight:900;
border-bottom:1px solid #EAEAEA;
padding-bottom:5px;
padding-right:7px;
}
ci{
color:black;
text-transform: uppercase;
margin-left:1px;
font-family:calibri;
border-bottom:1px solid #EAEAEA;
padding-bottom:5px;
font-weight:200;
position: relative;
font-size:15px;
color: black;
width: fit-content;
margin-left:1px
}
ci:after {
content: "";
border-bottom:1px solid black;
width: 100%;
height: 120%;
position: absolute;
top: -5px;
z-index: 1;
right:0px;
transition: 2.5s;
}
#deetz ci:hover:after{
border-bottom:1px solid black;
transition: 2.5s;
width:0%;
}
最佳答案
我试图或多或少地理解您的问题,您希望在将鼠标悬停在整个 lk 元素上时激活伪悬停。如果是这样,请尝试将悬停伪类添加到 lk 元素并使用 > 选择器指示它需要影响的元素
lk:hover > ci:after{
border-bottom:1px solid black;
transition: 2.5s;
width:0%;
}
关于html - 使伪元素在悬停在其父元素的父标签上时移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53037558/