Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SCSS multiple selectors

Hi i have this code:

.navbar .nav-pills .active > a {  
  background-color: $NavBgHighlight;  
  color: $NavTxtColor;  
}    
.navbar .nav-pills .active > a:hover {  
  background-color: $NavBgHighlight;  
  color: $NavTxtColor;  
}

I wanted to merge both of the sections into one section, something more like:

 .navbar .nav-pills .active > a, a:hover {  
  background-color: $NavBgHighlight;  
  color: $NavTxtColor;  
}   

But it doesnt work that way :( how can i merge both of them? ( I want that the :hover and the normal a will act the same)

like image 738
kfir124 Avatar asked Jun 07 '14 17:06

kfir124


People also ask

How do I select multiple classes in SCSS?

SASS/SCSS code to select multiple select classes in the same item. In SCSS, parent selector & symbol is used. This & will be resolved side by side after compilation for CSS.

How do I use multiple selectors in CSS?

Example# When you group CSS selectors, you apply the same styles to several different elements without repeating the styles in your style sheet. Use a comma to separate multiple grouped selectors. So the blue color applies to all <div> elements and all <p> elements.

How do you group selectors CSS?

To group selectors, separate each selector with a comma.


1 Answers

You can use SASS selector nesting:

.navbar .nav-pills .active {
    > a, > a:hover {
        background-color: $NavBgHighlight;  
        color: $NavTxtColor;  
    }
}    

Which compiles to:

.navbar .nav-pills .active > a, .navbar .nav-pills .active > a:hover {
    ... 
}
like image 127
jsalonen Avatar answered Oct 06 '22 21:10

jsalonen