Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sass Nesting for :hover does not work [duplicate]

I've written this code, but it does not work. What is my problem?

.class {     margin:20px;     :hover {         color:yellow;     }  } 
like image 928
Beach Boys Avatar asked Apr 13 '13 02:04

Beach Boys


People also ask

Why is hover not working CSS?

To solve the issue, you need to go over the CSS hover code to establish if you use the right selector. As well, ensure you use an opening curly bracket ({) after each selector and a closing curly bracket (}) at the end of the property list.

How does nesting work in SASS?

Nesting is a shortcut to creating CSS rules. Nesting in SASS works as selector of multiple CSS and combine them within one another instead of writing different CSS lines just to be precise about the style that we want to add to an element, we just nest it up.

Is SASS and SCSS same?

SASS (Syntactically Awesome Style Sheets) is a pre-processor scripting language that will be compiled or interpreted into CSS. SassScript is itself a scripting language whereas SCSS is the main syntax for the SASS which builds on top of the existing CSS syntax.


2 Answers

For concatenating selectors together when nesting, you need to use the parent selector (&):

.class {     margin:20px;     &:hover {         color:yellow;     } } 
like image 180
Sinac Avatar answered Sep 30 '22 20:09

Sinac


You can easily debug such things when you go through the generated CSS. In this case the pseudo-selector after conversion has to be attached to the class. Which is not the case. Use "&".

http://sass-lang.com/documentation/file.SASS_REFERENCE.html#parent-selector

.class {     margin:20px;     &:hover {         color:yellow;     } } 
like image 21
Enrico Stahn Avatar answered Sep 30 '22 18:09

Enrico Stahn