Questions tagged [sass]

Sass (Syntactically Awesome Style Sheets) is an extension of CSS adding features like nested rules, variables, mixins and class extensions. This enables developers to write structured, manageable and reusable CSS. Sass is compiled into standard CSS. It is primarily a CSS pre-processor language that accepts both the CSS and its personalised syntax of writing visual design codes.

Overview:

Sass is a meta-language on top of that describes the style of a document cleanly and structurally, with more power than flat CSS allows.

Sass is an extension of written in . It adds nested rules, variables, mixins, selector inheritance, and useful functions like color manipulation or conditional statements2. It's translated to well-formatted, standard CSS using the command-line tool or a web-framework plugin.

It is the only language that can store design tokens (e.g. colors, font sizes, spacing) and use the value types9 natively; i.e. numbers, colors, strings, lists, and booleans.

Sass has two syntaxes:

  1. SCSS (Sassy CSS): As of Sass3, this is the main syntax. It is a superset of CSS3, so all valid CSS files are also valid SCSS. Files with this syntax have the extension .scss.

Example SCSS:

$margin: 12px;

li {
  .border {
    margin: $margin / 2;
  }
}
  1. SASS: The indented syntax. Instead of braces and semicolons, it uses line indentation to specify blocks (similar to Ruby's syntax). Files with this syntax have the extension .sass.

Example SASS:

$margin: 12px

li
  .border
    margin: $margin / 2

Frameworks / Extensions:

  • 4 is an extension of Sass which provides pre-defined cross-browser mixins and additional functionality like automated sprite-generation.
  • 5 is a simple and lightweight mixin library for Sass.

Flavors:

  • Ruby Sass1 is the original Ruby-based version of Sass.
  • LibSass6 is C/C++ port of the Sass precompiler. It compiles very quickly, can be embedded in other languages and binaries, and aims for feature parity with the original Ruby Sass.
  • Node Sass7 uses LibSass to compile .scss files using Node.

Links:


Resources:

27250 questions
81
votes
1 answer

What does '&.' in '&.sub-title' indicates in scss?

I am a newbie to CSS and SCSS. In the following code, .title { width: 718px; &.sub-title { width: 938px; } } What does &. means? Is it same as nesting class?
nkm
  • 5,844
  • 2
  • 24
  • 38
80
votes
18 answers

Error: Cannot find module 'gulp-sass'

When I compile with gulp, I got an error like below. How can I fix it? module.js:339 throw err; ^ Error: Cannot find module 'gulp-sass' at Function.Module._resolveFilename (module.js:337:15) at Function.Module._load (module.js:287:25) at…
Htet Win
  • 801
  • 1
  • 6
  • 4
79
votes
2 answers

SASS (not SCSS) syntax for css3 keyframe animation

Is there any way to write keyframes in SASS? Every example I have found is actually SCSS, even when it says it's SASS. To be clear, I mean the one with no curly brackets.
daviestar
  • 4,531
  • 3
  • 29
  • 47
78
votes
9 answers

Webpack5 Automatic publicPath is not supported in this browser

I was working on webpack 4.44.2, I face this error when I convert to webpack5.0.0 ERROR in ./src/assets/sass/styles.scss Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js): Error: Automatic publicPath is not supported…
entesar
  • 929
  • 1
  • 8
  • 12
78
votes
6 answers

Multiple two-class selectors in Sass

Having multiple two-class selectors for a single declaration block, is it possible to simplify the following (i.e. not having to repeat the body tag): body.shop, body.contact, body.about, body.faq {background-color:#fff;}
Fellow Stranger
  • 32,129
  • 35
  • 168
  • 232
78
votes
2 answers

Using multiple conditions (AND) in SASS IF statement

Using SASS, I would like to have multiple condition in IF statement What I use right now : @function color-x ($alpha) { @if $accent == red {@return red($alpha)} @else if $accent == green {@return green($alpha)} @else if $accent…
500
  • 6,509
  • 8
  • 46
  • 80
77
votes
1 answer

What's the difference between @import and @use SCSS rules?

When to use SCSS rule: @use and when to use @import? What is the difference between them and the best-case scenarios to use them? @use '_styles.scss'; @import '_styles.scss';
Cosmina Palade
  • 885
  • 1
  • 5
  • 10
77
votes
12 answers

SASS implementation for Java?

I'm looking for SASS implementation in Java (could be used with JSP/JSF). For Python I've found CleverCSS, but there is nothing for Java. Anyone heard something about this sort of tool for generating CSS?
user213225
  • 879
  • 1
  • 7
  • 3
74
votes
3 answers

How do I add Sass compilation in Angular CLI 6: angular.json?

I just created a new Angular project using the new Angular CLI 6.0, but I need to add Sass compilation to my project. I'm aware you can set a flag when you create a project, but my project is already created and work has been done. The new…
Esten
  • 1,385
  • 2
  • 12
  • 21
74
votes
1 answer

How to overwrite SCSS variables when compiling to CSS

I'm trying to use jqtouch theming which is based on SASS and COMPASS. I have a file custom.scss with the most simple code, one import and one variable to overwrite: @import 'jqtouch'; // Override variables $base-color: #fe892a; /* The default base…
bouscher
  • 1,300
  • 1
  • 9
  • 18
73
votes
4 answers

False positive "undefined variable" error when compiling SCSS

Getting an error message when compiling my SCSS using the ruby compass gem. run: /var/lib/gems/1.8/gems/compass-0.12.2/bin/compass compile out: unchanged sass/partial/grid.scss out: error sass/partial/catalog.scss (Line 5: Undefined variable:…
kalenjordan
  • 2,446
  • 1
  • 24
  • 38
72
votes
5 answers

How to use Bootstrap 4 with SASS in Angular

I'd like to use Bootstrap 4 with SASS in an Angular(4+) project created with Angular CLI. In particular I need to: use SASS instead of CSS both as global style and Component-style compile Bootstrap SASS source together with my custom *.scss…
Francesco Borzi
  • 56,083
  • 47
  • 179
  • 252
71
votes
11 answers

How to use Sass in Visual Studio 2013

How can I use the Sass CSS preprocessor in Visual Studio 2013? Are there any extensions that provide support for Sass?
Hamed mayahian
  • 2,465
  • 6
  • 27
  • 49
71
votes
4 answers

SASS and @font-face

I have the following CSS - how would I describe it in SASS? I've tried reverse compiling it with css2sass, and just keep getting errors.... is it my CSS (which works ;-) )? @font-face { font-family: 'bingo'; src: url("bingo.eot"); src:…
Dycey
  • 4,767
  • 5
  • 47
  • 86
70
votes
4 answers

CSS-Only Sticky Table Headers In Chrome

I have the following Sass snippet in which I want the to float as the table scrolls. This works properly in Safari, but not in Chrome Version 58.0.3029.110 (64-bit). I know that Chrome has had on-again-off-again support for sticky, and…
Donnie
  • 6,229
  • 8
  • 35
  • 53