What's the difference between SCSS and Sass?

前端 未结 13 2106
忘掉有多难
忘掉有多难 2020-11-22 14:51

From what I\'ve been reading, Sass is a language that makes CSS more powerful with variable and math support.

What\'s the difference with SCSS? Is it supposed to be

13条回答
  •  无人共我
    2020-11-22 15:03

    Its syntax is different, and that's the main pro (or con, depending on your perspective).

    I'll try not to repeat much of what others said, you can easily google that but instead, I'd like to say a couple of things from my experience using both, sometimes even in the same project.

    SASS pro

    • cleaner - if you are coming from Python, Ruby (you can even write props with symbol-like syntax) or even the CoffeeScript world, it will come very natural to you - writing mixins, functions and generally any reusable stuff in .sass is much 'easier' and readable than in .scss (subjective).

    SASS cons

    • whitespace sensitive (subjective), I don't mind it in other languages but here in CSS it just bothers me (issues: copying, tab vs space war, etc).
    • no inline rules (this was game breaking for me), you can't do body color: red like you can in .scss body {color: red}
    • importing other vendor stuff, copying vanilla CSS snippets - not impossible but very boring after some time. The solution is to either have .scss files (alongside with .sass files) in your project or to convert them to .sass.

    Other than this - they do the same job.

    Now, what I like to do is to write mixins and variables in .sass and code that will actually compile to CSS in .scss if possible (ie Visual studio doesn't have support for .sass but whenever I work on Rails projects I usually combine two of them, not in one file ofc).

    Lately, I'm considering giving Stylus a chance (for a full-time CSS preprocessor) because it allows you to combine two syntaxes in one file (among some other features). That may not be a good direction for a team to take but when you are maintaining it alone - it's ok. The stylus is actually most flexible when syntax is in question.

    And finaly mixin for .scss vs .sass syntax comparison:

    // SCSS
    @mixin cover {
      $color: red;
      @for $i from 1 through 5 {
        &.bg-cover#{$i} { background-color: adjust-hue($color, 15deg * $i) }
      }
    }
    .wrapper { @include cover }
    
    
    // SASS
    =cover
      $color: red
      @for $i from 1 through 5
        &.bg-cover#{$i}
          background-color: adjust-hue($color, 15deg * $i)
    .wrapper
      +cover
    

提交回复
热议问题