CSS SASS :after :hover 选择器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36946141/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 11:55:06  来源:igfitidea点击:

SASS :after :hover selector

csssasscss-selectors

提问by Alexander Graham

How do I use a SASS selector within a pseudo selector on a hover state? Wanting to write less code and clean this up.

如何在悬停状态的伪选择器中使用 SASS 选择器?想要编写更少的代码并清理它。

Preferred method, not working:

首选方法,不起作用:

div {
    a {
        transition: all 0.25s ease-in-out;
        &:after {
            content: ">>";
            left: 10px;
            :hover & {
                left: 10px;
            }
        }
    }
}

As opposed to:

与之相反:

div {
    a {
        transition: all 0.25s ease-in-out;
        &:after {
            content: ">>";
            left: 10px;
        }
        &:hover {
            &:after {
                left: 10px;
            }
        }
    }
}

回答by Jan Franta

Use &:hover:after {}for targeting the afterpseudo-element of the element being hovered over.

使用&:hover:after {}了针对after该元件的伪元素上空盘旋。

&:after:hover {}would select the afterpseudo-element and used on hover it.

&:after:hover {}将选择after伪元素并用于悬停它。