我想在悬停在主 div
上时触发多个悬停效果。我无法弄清如何同时使所有三个链接上的线条动画化,以及是否只能使用 CSS 还是必须使用 JavaScript,并且我没有找到之前帖子的正确解决方案。这是代码:
.right-project-headline h2 a {
text-decoration: none;
color: black;
position: relative;
}
.right-project-headline h2 a::before, .right-project-headline h2 a::after {
content: '';
background: black;
position: absolute;
top: 55%;
height: 3px;
width: 0;
}
.right-project-headline h2 a::before {
left: 0;
}
.right-project-headline h2 a::after {
right: 0;
transition: width 500ms ease;
}
.right-project-headline h2 a:hover::before {
width: 100%;
transition: width 500ms ease;
}
.right-project-headline h2 a:hover::after {
width: 100%;
background: transparent;
transition: 0;
}
<div class="right-project-headline">
<h2><a href="industrial-rev.html">The</a></h2>
<h2><a href="industrial-rev.html">Industrial</a></h2>
<h2><a href="industrial-rev.html">Revolutions</a></h2>
</div>