Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SASS :after :hover selector [duplicate]

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

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;
            }
        }
    }
}
like image 300
Alexander Graham Avatar asked Apr 29 '16 19:04

Alexander Graham


1 Answers

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

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

like image 66
Jan Franta Avatar answered Nov 11 '22 20:11

Jan Franta