在悬停相同元素的同时,有什么方法可以激活“之后”的伪元素?

问题描述 投票:0回答:1

在悬停li元素期间,我想在列表菜单中将图片作为边框的底部添加。

li:hover li:after{
        content: "";
        display: block;
        background-image: url("http://placehold.it/350x65");
        background-repeat: no-repeat;
        background-position: center bottom;
    }

有什么办法吗?
html css
1个回答
2
投票

您已经接近,但是您编写它的方式导致li:after覆盖li:hover,您可以将两者结合在一起。

li:hover:after { ... }-当li悬停时更改after伪类。

li:after:hover { ... }-仅在将after本身悬停时才更改伪类。

请记住,在定义默认状态后,就像其他任何悬停定义一样,都应该添加这些。

© www.soinside.com 2019 - 2024. All rights reserved.