Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hover and active states in less

Tags:

css

less

Can you add an active state on the same line as a hover state in [less] or does it have to be nested on line separate lines?

example:

standard less

nav {
    color:@black;
    display:block;
    &:hover {color:@primary-color;}
    &:active {color:@primary-color;}    
}

somehow to do this

nav {
    color:@black;
    display:block;
    &:hover, &:active {color:@primary-color;}    
}

I've tried: [&:hover, &:active;] I've tried: [&:hover; &:active;] but it's doesn't seem to work.

like image 371
mayhemds Avatar asked May 17 '13 01:05

mayhemds


2 Answers

Actually yes you can, and the second variant you provided is correct as long as you define the @primary-color variable:

@primary-color: #f00;
@black: #000;

nav {
  color: @black;
  display:block;
  &:hover, &:active {color:@primary-color;}    
}

will produce:

nav {
  color: #000000;
  display: block;
}
nav:hover,
nav:active {
  color: #ff0000;
}
like image 122
Juicy Scripter Avatar answered Nov 11 '22 15:11

Juicy Scripter


It's late and my stupidity tells me to go to bed.

Juicy Scripter get's the win, I get the lose for back coding mistakes.

But yes,

nav {
  color: @black;
  display:block;
  &:hover, &:active {color:@primary-color;}    
}

Is the answer.

like image 39
mayhemds Avatar answered Nov 11 '22 17:11

mayhemds