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
158
votes
6 answers

Sass calculate percent minus px

I want to be able to do the following: height: 25% - 5px; Obviously when I do that I get the error: Incompatible units: 'px' and '%'.
Mike Fielden
  • 10,055
  • 14
  • 59
  • 99
157
votes
3 answers

How can I use custom theme palettes in Angular?

I want to use my company's brand colors throughout the app. I have found this issue: AngularJS 2 - Material design - set color palette where I can build an allegedly custom theme, but it's basically just using different parts of pre-built palettes.…
Narxx
  • 7,929
  • 5
  • 26
  • 34
154
votes
13 answers

Node.js Sass version 7.0.0 is incompatible with ^4.0.0 || ^5.0.0 || ^6.0.0

I used Node.js v16.13.1 and created a React application. I tried to use Sass, but when I tried to run it, I got this error: Node Sass version 7.0.0 is incompatible with ^4.0.0 || ^5.0.0 || ^6.0.0
anderson j mariño o.
  • 1,739
  • 2
  • 6
  • 7
149
votes
4 answers

Calculate a percent with SCSS/SASS

I want to set a width in percentage in scss via calculation, but it gives me errors.. Invalid CSS after "...-width: (4/12)%": expected expression (e.g. 1px, bold), was ";" I want to do something like $my_width: (4/12)%; div{ width:…
Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244
147
votes
2 answers

SassError: There is no module with the namespace "math"

I'm having trouble getting the math SASS library to work in a Vue app. It compiles with Dart Sass, and sass-loader. The Dart Sass version is 1.26.3, so the math module should work. Module build failed (from…
Chris Hayes
  • 11,505
  • 6
  • 33
  • 41
144
votes
2 answers

Sass and combined child selector

I've just discovered Sass, and I've been so excited about it. In my website I implement a tree-like navigation menu, styled using the child combinator (E > F). Is there any way to rewrite this code with a simpler (or better) syntax in Sass? #foo >…
frarees
  • 2,190
  • 3
  • 17
  • 22
141
votes
5 answers

Have a variable in images path in Sass?

I want to have one variable that contains the root path to all my images in my CSS file. I can't quite figure out if this is possible in pure Sass (the actual web project is not RoR, so can't use asset_pipeline or any of that fancy jazz). Here's my…
program247365
  • 3,951
  • 7
  • 33
  • 44
135
votes
6 answers

Sass negative variable value?

I have a couple of scss selectors where I use the same amount positive and negative, as in: padding: 0 15px 15px; margin: 0 -15px 20px -15px; I'd prefer to use a variable for all the 15px amounts, but this does not work: $pad: 15px; padding: 0 $pad…
Steve
  • 14,401
  • 35
  • 125
  • 230
134
votes
6 answers

Placeholder Mixin SCSS/CSS

I'm trying to create a mixin for placeholders in sass. This is the mixin I've created. @mixin placeholder ($css) { ::-webkit-input-placeholder {$css} :-moz-placeholder {$css} ::-moz-placeholder {$css} …
Shannon Hochkins
  • 11,763
  • 15
  • 62
  • 95
124
votes
8 answers

How to resolve "You need to have Ruby and Sass installed and in your PATH for this task to work" Warning?

I am in the process of setting up a new Mac for work. I have installed Grunt & Grunt CLI globally. Then I did a npm install inside a project folder to install all dependencies. No problems so far, but as soon as I try to run the sass:dist task, I…
Sven
  • 12,997
  • 27
  • 90
  • 148
121
votes
7 answers

Creating or referencing variables dynamically in Sass

I'm trying to use string interpolation on my variable to reference another variable: // Set up variable and mixin $foo-baz: 20px; @mixin do-this($bar) { width: $foo-#{$bar}; } // Use mixin by passing 'baz' string as a param for use $foo-baz…
Krzysztof Romanowski
  • 2,164
  • 2
  • 20
  • 29
120
votes
6 answers

Extending selectors from within media queries with Sass

I have an item class and a compact "modifier" class: .item { ... } .item.compact { /* styles to make .item smaller */ } This is fine. However, I'd like to add a @media query that forces the .item class to be compact when the screen is small…
soundly_typed
  • 39,257
  • 5
  • 28
  • 36
115
votes
3 answers

Syntax for if/else condition in SCSS mixin

Hi I'm trying to learn SASS/SCSS and am trying to refactor my own mixin for clearfix what I'd like is for the mixin to be based on whether I pass the mixin a width. thoughts so far (pseudo code only as I will be including other mixins) @mixin…
clairesuzy
  • 27,296
  • 8
  • 54
  • 52
115
votes
7 answers

Is there a SASS.js? Something like LESS.js?

I have used LESS.js before. It's easy to use, something like I saw SASS.js. How can I use it in a similar way? Parsing a SASS file…
Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
114
votes
4 answers

What does an "&" before a pseudo element in CSS mean?

In the following CSS taken from Twitter Bootstrap what does the ampersand (&) character mean? .clearfix { *zoom: 1; &:before, &:after { display: table; content: ""; } &:after { clear: both; } }
neodymium
  • 3,686
  • 6
  • 23
  • 31