26

Is it possible to do this with less?

a {
    &:after {
        background: red;
    }
    &:hover {
        &:after {
            background: blue;
        }
    }
}

I can't get the :after to change color when hovering over a?

Sergey
  • 995
  • 4
  • 14
  • 33
Philip
  • 6,827
  • 13
  • 75
  • 104

3 Answers3

56

The following works fine for me:

a {
    &:after {
        content:'a';
        background: red;
    }
    &:hover {
        &:after {
            background: blue;
        }
    }
}

My LESS-enabled editor, compiled that to:

a:after {
  content: 'a';
  background: red;
}
a:hover:after {
  background: blue;
}

Which does work.

Robert McKee
  • 21,305
  • 1
  • 43
  • 57
0

This is also work fine for me : -

 a{
    &:after{
        background: red;
        content: "Hover Text"
    }
    &:hover{
        &:after{
            background: yellow;
        }
    }
}

And My terminal Compile that to:-

a:after {
  background: red;
  content: "Hover Text";
}
a:hover:after {
  background: yellow;
}
Sunil R.
  • 851
  • 8
  • 15
-6
a {

  &:after {

     background: red;

  }

  &:hover,
  &:after {

     background: blue;

  }

}

This is okay now :P

miber
  • 1