5

I've been searching around. Found some similar questions on stackoverwflow and other resources, but most of them was regarding syntax mistakes.

Can somebody tell me what is wrong with this code and why SASS is not generating :hover in resulting css?

Here is my SASS code:

.img-ornament
    -webkit-transition: all 0.5s ease
    -moz-transition: all 0.5s ease
    -ms-transition: all 0.5s ease
    -o-transition: all 0.5s ease
    transition: all 0.5s ease
    &:hover
        -webkit-transform:scale(0.75)
        -moz-transform:scale(0.75)
        -ms-transform:scale(0.75)
        -o-transform:scale(0.75)
        transform:scale(0.75)

Here is resulting css:

.img-ornament {
    -webkit-transition: all 0.5s ease;
    -moz-transition: all 0.5s ease;
    -ms-transition: all 0.5s ease;
    -o-transition: all 0.5s ease;
    transition: all 0.5s ease;
}

Where is :hover portion?

here is sassmeister's gist https://gist.github.com/sayfulloev/396477b5a91f9511c8eb

1
  • 1
    Is it because you're missing your curly braces? {} from your SCSS.
    – Aaron
    Commented Oct 1, 2015 at 14:41

1 Answer 1

6

The SASS (indented) syntax is highly whitespace sensitive. If you convert your code to SCSS syntax, you'll get a clearer idea of how it is being interpreted:

.img-ornament {
  -webkit-transition: all 0.5s ease;
  -moz-transition: all 0.5s ease;
  -ms-transition: all 0.5s ease;
  -o-transition: all 0.5s ease;
  transition: all 0.5s ease;
  &:hover {
    -webkit-transform:scale(0.75) {}
    -moz-transform:scale(0.75) {}
    -ms-transform:scale(0.75) {}
    -o-transform:scale(0.75) {}
    transform:scale(0.75) {}
  }
}

The lack of whitespace after the colon is causing the SASS interpreter to treat transform:scale(0.75) as a selector, rather than as a property/value combination. Since your selector doesn't have any styles associated with it, Sass discards the information in the compiled results.

Note that this is limited to the official Ruby Sass compiler, LibSass does not appear to have this behavior.

TLDR;

Add whitespace after your colons.

.img-ornament
  -webkit-transition: all 0.5s ease
  -moz-transition: all 0.5s ease
  -ms-transition: all 0.5s ease
  -o-transition: all 0.5s ease
  transition: all 0.5s ease
  &:hover
    -webkit-transform: scale(0.75)
    -moz-transform: scale(0.75)
    -ms-transform: scale(0.75)
    -o-transform: scale(0.75)
    transform: scale(0.75)
1
  • Thanks for your help!
    – Sharif
    Commented Oct 1, 2015 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.