首页 > 解决方案 > 在将鼠标悬停在其父级的父级标签上时使伪元素移动

问题描述

我想让我的伪元素的边框在其父元素的父元素悬停时移动。基本上,当我将鼠标悬停在"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%;
}

标签: htmlcsstagspseudo-element

解决方案


我试图或多或少地理解您的问题,您希望在将鼠标悬停在整个 lk 元素上时激活伪悬停。如果是这样,请尝试将悬停伪类添加到 lk 元素并使用 > 选择器指示它需要影响的元素

lk:hover > ci:after{
border-bottom:1px solid black;
transition: 2.5s;
width:0%;
}

推荐阅读