Jump to content

Sass (style sheet language): Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Rescuing 3 sources and tagging 0 as dead.) #IABot (v2.0.9.5) (Whoop whoop pull up - 21816
 
(39 intermediate revisions by 19 users not shown)
Line 1: Line 1:
{{short description|Stylesheet language}}
{{short description|Stylesheet language}}
{{For|the software distribution scheme known as "SaaS"|Software as a service}}
{{For|the software distribution scheme known as "SaaS"|Software as a service}}
{{Primary sources|date=May 2024}}
{{Infobox programming language
{{Infobox programming language
| name = Sass
| name = Sass
Line 12: Line 13:
| website = {{URL|https://sass-lang.com/}}
| website = {{URL|https://sass-lang.com/}}
| released = {{Start date and age|2006|11|28}}
| released = {{Start date and age|2006|11|28}}
| latest_release_version = 1.54.0<ref name=latest-release>{{cite web|url=https://github.com/sass/dart-sass/blob/main/CHANGELOG.md|title=Dart Sass - latest release|website=github.com}}</ref>
| latest_release_version = 1.75.0<ref name=latest-release>{{cite web|url=https://github.com/sass/dart-sass/blob/main/CHANGELOG.md|title=Dart Sass - latest release|website=github.com}}</ref>
| latest_release_date = {{Start date and age|2022|07|07}}<ref name=latest-release/>
| latest_release_date = {{Start date and age|2024|04|11}}<ref name=latest-release/>
| influenced_by = [[CSS]] (both "indented" and SCSS)
| influenced_by = [[CSS]] (both "indented" and SCSS)
[[YAML]] and [[Haml]] (indented syntax)
[[YAML]] and [[Haml]] (indented syntax)
Line 22: Line 23:
'''Sass''' (short for '''''syntactically awesome style sheets''''') is a [[preprocessor]] [[scripting language]] that is [[Interpreted language|interpreted]] or [[Compiled language|compiled]] into [[CSS|Cascading Style Sheets]] (CSS). SassScript is the scripting language itself.
'''Sass''' (short for '''''syntactically awesome style sheets''''') is a [[preprocessor]] [[scripting language]] that is [[Interpreted language|interpreted]] or [[Compiled language|compiled]] into [[CSS|Cascading Style Sheets]] (CSS). SassScript is the scripting language itself.


Sass consists of two [[Syntax (programming languages)|syntaxes]]. The original syntax, called "the indented syntax," uses a syntax similar to [[Haml]].<ref name="main">{{cite web |author=Media Mark (3.2.12) |title=Sass - Syntactically Awesome Stylesheets |url=http://sass-lang.com/ |access-date=2014-02-23 |publisher=Sass-lang.com |language=en-US}}</ref> It uses [[Indent style|indentation]] to separate [[block (programming)|code blocks]] and [[newline]] characters to separate rules. The newer syntax, '''SCSS''' (Sassy CSS), uses block formatting like that of CSS. It uses braces to denote code blocks and semicolons to separate rules within a block. The indented syntax and SCSS files are traditionally given the [[filename extension|extensions]] .sass and .scss, respectively.
Sass consists of two [[Syntax (programming languages)|syntaxes]]. The original syntax, called "the indented syntax," uses a syntax similar to [[Haml]].<ref name="main">{{cite web |author=Media Mark (3.2.12) |title=Sass - Syntactically Awesome Stylesheets |url=http://sass-lang.com/ |access-date=2014-02-23 |publisher=Sass-lang.com |language=en-US}}</ref><ref name="o'reilly"/> It uses [[Indent style|indentation]] to separate [[block (programming)|code blocks]] and [[newline]] characters to separate rules. The newer syntax, '''SCSS''' (Sassy CSS), uses block formatting like that of CSS. It uses braces to denote code blocks and semicolons to separate rules within a block. The indented syntax and SCSS files are traditionally given the [[filename extension|extensions]] .sass and .scss, respectively.<ref>{{Cite book |last=Libby |first=Alex |date=2019 |title=Introducing Dart Sass: A Practical Introduction to the Replacement for Sass, Built on Dart |url=http://link.springer.com/10.1007/978-1-4842-4372-5 |language=en |location=Berkeley, CA |publisher=Apress |doi=10.1007/978-1-4842-4372-5 |isbn=978-1-4842-4371-8}}</ref>


[[CSS#CSS 3|CSS3]] consists of a series of selectors and pseudo-selectors that group rules that apply to them. Sass (in the larger context of both syntaxes) extends CSS by providing several mechanisms available in more traditional [[programming language]]s, particularly [[object-oriented programming|object-oriented languages]], but that are not available to CSS3 itself. When SassScript is interpreted, it creates blocks of CSS rules for various selectors as defined by the Sass file. The Sass interpreter translates SassScript into CSS. Alternatively, Sass can monitor the .sass or .scss file and translate it to an output .css file whenever the .sass or .scss file is saved.<ref name="tutorial">[http://sass-lang.com/tutorial.html Sass - Syntactically Awesome Stylesheets] Tutorial</ref>
[[CSS#CSS 3|CSS3]] consists of a series of selectors and pseudo-selectors that group rules that apply to them. Sass (in the larger context of both syntaxes) extends CSS by providing several mechanisms available in more traditional [[programming language]]s, particularly [[object-oriented programming|object-oriented languages]], but that are not available to CSS3 itself. When SassScript is interpreted, it creates blocks of CSS rules for various selectors as defined by the Sass file. The Sass interpreter translates SassScript into CSS. Alternatively, Sass can monitor the .sass or .scss file and translate it to an output .css file whenever the .sass or .scss file is saved.<ref name="tutorial">[http://sass-lang.com/tutorial.html Sass - Syntactically Awesome Stylesheets] {{Webarchive|url=https://web.archive.org/web/20131009053354/http://sass-lang.com/tutorial.html |date=2013-10-09 }} Tutorial</ref>


The indented syntax is a metalanguage. SCSS is a [[metalanguage#Nested|nested metalanguage]] and a [[superset]] of CSS, as valid CSS is valid SCSS with the same [[semantics of programming languages|semantics]].
The indented syntax is a metalanguage. SCSS is a [[metalanguage#Nested|nested metalanguage]] and a [[superset]] of CSS, as valid CSS is valid SCSS with the same [[semantics of programming languages|semantics]].


SassScript provides the following mechanisms: [[variable (programming)|variable]]s, [[nesting (computing)#In programming|nesting]], [[mixin]]s, and selector [[inheritance (computer science)|inheritance]].<ref name="main" />
SassScript provides the following mechanisms: [[variable (programming)|variable]]s, [[nesting (computing)#In programming|nesting]], [[mixin]]s,<ref name="o'reilly">{{Cite book |last=Firtman |first=Maximiliano |url=https://books.google.com/books?id=gswdarRZVUoC |title=Programming the Mobile Web |date=2013-03-15 |publisher=O'Reilly Media, Inc. |isbn=978-1-4493-3497-0 |language=en}}</ref> and selector [[inheritance (computer science)|inheritance]].<ref name="main" />


== History ==
== History ==
Sass was initially designed by [[Hampton Catlin]] and developed by Natalie Weizenbaum.<ref name="about">{{cite web|title=Sass: Syntactically Awesome Style Sheets|url=http://sass-lang.com/about.html|url-status=dead|archive-url=https://web.archive.org/web/20130901145805/http://sass-lang.com/about.html|archive-date=2013-09-01|work=sass-lang.com}}</ref><ref>{{cite web|title=Natalie Weizenbaum's blog|url=http://nex-3.com/|url-status=dead|archive-url=https://web.archive.org/web/20071011121541/http://nex-3.com/|archive-date=2007-10-11}}</ref> After its initial versions, Weizenbaum and Chris Eppstein have continued to extend Sass with SassScript, a scripting language used in Sass files.
Sass was initially designed by [[Hampton Catlin]] and developed by Natalie Weizenbaum.<ref name="about">{{cite web|title=Sass: Syntactically Awesome Style Sheets|url=http://sass-lang.com/about.html|url-status=dead|archive-url=https://web.archive.org/web/20130901145805/http://sass-lang.com/about.html|archive-date=2013-09-01|work=sass-lang.com}}</ref><ref>{{cite web|title=Natalie Weizenbaum's blog|url=http://nex-3.com/|url-status=dead|archive-url=https://web.archive.org/web/20071011121541/http://nex-3.com/|archive-date=2007-10-11}}</ref>


== Major implementations ==
== Major implementations ==
Line 39: Line 40:
* The official "sass" [[Node.js|node]] module on [[npm]], which is Dart Sass compiled to pure JavaScript.<ref>{{cite web|url=https://www.npmjs.com/package/sass|title=sass|website=www.npmjs.com}}</ref>
* The official "sass" [[Node.js|node]] module on [[npm]], which is Dart Sass compiled to pure JavaScript.<ref>{{cite web|url=https://www.npmjs.com/package/sass|title=sass|website=www.npmjs.com}}</ref>
* The official "sass-embedded" node module which is a JavaScript wrapper around the native Dart executable.<ref>{{cite web|url=https://www.npmjs.com/package/sass-embedded|title=sass-embedded|website=www.npmjs.com}}</ref>
* The official "sass-embedded" node module which is a JavaScript wrapper around the native Dart executable.<ref>{{cite web|url=https://www.npmjs.com/package/sass-embedded|title=sass-embedded|website=www.npmjs.com}}</ref>
* The original [[Open-source software|open-source]] [[Ruby (programming language)|Ruby]] implementation created in 2006,<ref name=":0">{{cite web|url=http://drupal.org/project/sass|title=Sass / Scss|date=2009-10-21|publisher=Drupal.org|access-date=2014-02-23}}</ref> since deprecated due to the lack of maintainers and reached End-of-Life in March 2019.<ref>{{Cite web|url=http://sass.logdown.com/posts/7828841-ruby-sass-is-unsupported|title=Ruby Sass Has Reached End-Of-Life « Sass Blog|last=Weizenbaum|first=Natalie|website=sass.logdown.com|access-date=2019-04-21}}</ref><ref>{{Cite web|url=https://sass-lang.com/ruby-sass|title=Sass: Ruby Sass|website=sass-lang.com|access-date=2019-04-21}}</ref>
* The original [[Open-source software|open-source]] [[Ruby (programming language)|Ruby]] implementation created in 2006,<ref name=":0">{{cite web|url=http://drupal.org/project/sass|title=Sass / Scss|date=2009-10-21|publisher=Drupal.org|access-date=2014-02-23|archive-date=2016-03-10|archive-url=https://web.archive.org/web/20160310210318/https://www.drupal.org/project/sass|url-status=dead}}</ref> since deprecated due to the lack of maintainers and reached End-of-Life in March 2019.<ref>{{Cite web|url=http://sass.logdown.com/posts/7828841-ruby-sass-is-unsupported|title=Ruby Sass Has Reached End-Of-Life « Sass Blog|last=Weizenbaum|first=Natalie|website=sass.logdown.com|access-date=2019-04-21}}</ref><ref>{{Cite web|url=https://sass-lang.com/ruby-sass|title=Sass: Ruby Sass|website=sass-lang.com|access-date=2019-04-21}}</ref>
* libSass, the official open-source [[C++]] implementation, deprecated in October 2020.<ref>{{cite web|url=https://sass-lang.com/blog/libsass-is-deprecated|title=LibSass is Deprecated|website=sass-lang.com|date=26 October 2020}}</ref>
* libSass, the official open-source [[C++]] implementation, deprecated in October 2020.<ref>{{cite web|url=https://sass-lang.com/blog/libsass-is-deprecated|title=LibSass is Deprecated|website=sass-lang.com|date=26 October 2020}}</ref>
*The deprecated "node-sass" node module on [[Npm (software)|npm]], based on the deprecated libSass.<ref>{{cite web|url=https://www.npmjs.com/package/node-sass|title=node-sass|website=www.npmjs.com}}</ref>
*The deprecated "node-sass" node module on [[Npm (software)|npm]], based on the deprecated libSass.<ref>{{cite web|url=https://www.npmjs.com/package/node-sass|title=node-sass|website=www.npmjs.com}}</ref>
Line 349: Line 350:
== libSass ==
== libSass ==
At the 2012 HTML5 Developer Conference, Hampton Catlin, the creator of Sass, announced version 1.0 of libSass, an open source C++ implementation of Sass developed by Catlin, Aaron Leung, and the engineering team at [[Moovweb]].<ref name="libsass-html5conf">{{cite web|url=https://www.youtube.com/watch?v=j75-SslllvY&feature=player_detailpage#t=1831s |archive-url=https://ghostarchive.org/varchive/youtube/20211215/j75-SslllvY |archive-date=2021-12-15 |url-status=live|title=Hampton's 6 Rules of Mobile Design|author=H. Catlin|date=2012-10-15|publisher=HTML5 Developer Conference|access-date=2013-07-11}}{{cbignore}}</ref><ref name="libsass-moovweb-blog">{{cite web
At the 2012 HTML5 Developer Conference, Hampton Catlin, the creator of Sass, announced version 1.0 of libSass, an open source C++ implementation of Sass developed by Catlin, Aaron Leung, and the engineering team at [[Moovweb]].<ref name="libsass-html5conf">{{cite web|url=https://www.youtube.com/watch?v=j75-SslllvY&feature=player_detailpage#t=1831s |archive-url=https://ghostarchive.org/varchive/youtube/20211215/j75-SslllvY |archive-date=2021-12-15 |url-status=live|title=Hampton's 6 Rules of Mobile Design|author=H. Catlin|date=2012-10-15|publisher=HTML5 Developer Conference|access-date=2013-07-11}}{{cbignore}}</ref><ref name="libsass-moovweb-blog">{{cite web
|url = http://blog.moovweb.com/2012/04/libsass/
|url = http://blog.moovweb.com/2012/04/libsass/
|title = libsass
|title = libsass
|publisher = Moovweb Blog
|publisher = Moovweb Blog
|date = 2012-04-30
|date = 2012-04-30
|access-date = 2013-07-11
|access-date = 2013-07-11
|author = M. Catlin
|author = M. Catlin
|url-status = dead
|url-status = dead
|archive-url = https://web.archive.org/web/20130508080521/http://blog.moovweb.com/2012/04/libsass/
|archive-url = https://web.archive.org/web/20130508080521/http://blog.moovweb.com/2012/04/libsass/
|archive-date = 2013-05-08
|archive-date = 2013-05-08
}}</ref>
}}</ref> Current Sass maintainer Chris Eppstein has expressed intent to contribute as well.<ref>{{cite tweet
| user=chriseppstein
| number=323845132417900544
| title=Good resources on writing production, x-platform C++? I haven't coded any since college but I want to hack on libsass /cc @hcatlin @akhleung
| date=2013-04-15
| access-date=2021-03-19
| author=C. Eppstein}}</ref>


According to Catlin, libSass can be "drop[ped] into anything and it will have Sass in it...You could drop it right into Firefox today and build Firefox and it will compile in there. We wrote our own parser from scratch to make sure that would be possible."<ref>{{cite web
According to Catlin, libSass can be "drop[ped] into anything and it will have Sass in it...You could drop it right into Firefox today and build Firefox and it will compile in there. We wrote our own parser from scratch to make sure that would be possible."<ref>{{cite web
| url=http://5by5.tv/changelog/94
| url=http://5by5.tv/changelog/94
| title=Sass, libsass, Haml and more with Hampton Catlin
| title=Sass, libsass, Haml and more with Hampton Catlin
| date=2013-06-26
| date=2013-06-26
| access-date=2013-07-30
| access-date=2013-07-30
| author=A. Stacoviak & A. Thorp
| author=A. Stacoviak & A. Thorp
| archive-date=2013-08-06
| archive-date=2013-08-06
| archive-url=https://web.archive.org/web/20130806073554/http://5by5.tv/changelog/94
| archive-url=https://web.archive.org/web/20130806073554/http://5by5.tv/changelog/94
| url-status=dead
| url-status=dead
}}</ref>
}}</ref>


The design goals of libSass are:
The design goals of libSass are:
* Performance&nbsp;– Developers have reported 10x speed up increases over the Ruby implementation of Sass.<ref>{{cite web
* Performance&nbsp;– Developers have reported 10x speed up increases over the Ruby implementation of Sass.<ref>{{cite web
| url=http://www.damln.com/log/sassc-and-bourbon-it-works/
| url=http://www.damln.com/log/sassc-and-bourbon-it-works/
| title=Sassc and Bourbon
| title=Sassc and Bourbon
| date=2013-06-07
| date=2013-06-07
| access-date=2013-07-11
| access-date=2013-07-11
| author=D. Le Nouaille}}</ref>
| author=D. Le Nouaille
}}</ref>
* Easier integration&nbsp;– libSass makes it easier to integrate Sass into more software. Before libSass, tightly integrating Sass into a language or software product required bundling the entire Ruby interpreter. By contrast, libSass is a statically linkable library with zero external dependencies and C-like interface, making it easy to wrap Sass directly into other programming languages and tools. For example, open source libSass bindings now exist for [[Node.js|Node]], [[Go (programming language)|Go]], and [[Ruby programming language|Ruby]].<ref name="libsass-moovweb-blog" />
* Easier integration&nbsp;– libSass makes it easier to integrate Sass into more software. Before libSass, tightly integrating Sass into a language or software product required bundling the entire Ruby interpreter. By contrast, libSass is a statically linkable library with zero external dependencies and C-like interface, making it easy to wrap Sass directly into other programming languages and tools. For example, open source libSass bindings now exist for [[Node.js|Node]], [[Go (programming language)|Go]], and [[Ruby (programming language)|Ruby]].<ref name="libsass-moovweb-blog" />
* Compatibility&nbsp;– libSass's goal is full compatibility with the official Ruby implementation of Sass. This goal has been achieved on libsass 3.3.<ref>{{Cite web|url=http://sass-compatibility.github.io/|title=Sass Compatibility|website=sass-compatibility.github.io|access-date=2019-11-29}}</ref>
* Compatibility&nbsp;– libSass's goal is full compatibility with the official Ruby implementation of Sass. This goal has been achieved on libsass 3.3.<ref>{{Cite web|url=http://sass-compatibility.github.io/|title=Sass Compatibility|website=sass-compatibility.github.io|access-date=2019-11-29|archive-date=2019-12-05|archive-url=https://web.archive.org/web/20191205161602/http://sass-compatibility.github.io/|url-status=dead}}</ref>


== IDE integration ==
== IDE integration ==
Line 441: Line 437:
|
|
|}
|}

== See also ==
== See also ==
* [[Less (style sheet language)]]
* [[Less (style sheet language)]]
Line 448: Line 443:
== References ==
== References ==
{{Reflist|30em}}
{{Reflist|30em}}

== Further reading ==
* {{Cite journal |last1=Ndia |first1=John Gichuki |last2=Muketha |first2=Geoffrey Muchiri |last3=Omieno |first3=Kelvin Kabeti |date=2019 |title=Complexity Metrics for Sassy Cascading Style Sheets |url=http://www.bjmc.lu.lv/fileadmin/user_upload/lu_portal/projekti/bjmc/Contents/7_4_01_Ndia.pdf |journal=Baltic Journal of Modern Computing |volume=7 |issue=4 |doi=10.22364/bjmc.2019.7.4.01}}
* {{Cite book |last=Cederholm |first=Dan |title=Sass for Web Designers |publisher=A Book Apart |year=2013 |isbn=978-1-937557-13-3 |url=https://jayakarta.ac.id/assets/front/example.pdf}}
* {{Cite book |last=Watts |first=Luke |title=Mastering Sass |publisher=Packt Publishing |year=2016 |url=https://books.google.com/books?id=pUrWDQAAQBAJ}}


== External links ==
== External links ==

Latest revision as of 01:09, 19 November 2024

Sass
Designed byHampton Catlin
DeveloperNatalie Weizenbaum, Chris Eppstein
First appearedNovember 28, 2006; 18 years ago (2006-11-28)
Stable release
1.75.0[1] / April 11, 2024; 8 months ago (2024-04-11)[1]
Typing disciplineDynamic
OSCross-platform
LicenseMIT License
Filename extensions.sass, .scss
Websitesass-lang.com
Major implementations
Dart
Influenced by
CSS (both "indented" and SCSS)

YAML and Haml (indented syntax)

Less (SCSS)
Influenced
Less, Stylus, Tritium, Bootstrap (v4+)

Sass (short for syntactically awesome style sheets) is a preprocessor scripting language that is interpreted or compiled into Cascading Style Sheets (CSS). SassScript is the scripting language itself.

Sass consists of two syntaxes. The original syntax, called "the indented syntax," uses a syntax similar to Haml.[2][3] It uses indentation to separate code blocks and newline characters to separate rules. The newer syntax, SCSS (Sassy CSS), uses block formatting like that of CSS. It uses braces to denote code blocks and semicolons to separate rules within a block. The indented syntax and SCSS files are traditionally given the extensions .sass and .scss, respectively.[4]

CSS3 consists of a series of selectors and pseudo-selectors that group rules that apply to them. Sass (in the larger context of both syntaxes) extends CSS by providing several mechanisms available in more traditional programming languages, particularly object-oriented languages, but that are not available to CSS3 itself. When SassScript is interpreted, it creates blocks of CSS rules for various selectors as defined by the Sass file. The Sass interpreter translates SassScript into CSS. Alternatively, Sass can monitor the .sass or .scss file and translate it to an output .css file whenever the .sass or .scss file is saved.[5]

The indented syntax is a metalanguage. SCSS is a nested metalanguage and a superset of CSS, as valid CSS is valid SCSS with the same semantics.

SassScript provides the following mechanisms: variables, nesting, mixins,[3] and selector inheritance.[2]

History

[edit]

Sass was initially designed by Hampton Catlin and developed by Natalie Weizenbaum.[6][7]

Major implementations

[edit]

SassScript was implemented in multiple languages, the noteworthy implementations are:

  • The official open-source Dart implementation.[8]
  • The official "sass" node module on npm, which is Dart Sass compiled to pure JavaScript.[9]
  • The official "sass-embedded" node module which is a JavaScript wrapper around the native Dart executable.[10]
  • The original open-source Ruby implementation created in 2006,[8] since deprecated due to the lack of maintainers and reached End-of-Life in March 2019.[11][12]
  • libSass, the official open-source C++ implementation, deprecated in October 2020.[13]
  • The deprecated "node-sass" node module on npm, based on the deprecated libSass.[14]
  • JSass, an unofficial Java implementation,[15] based on the deprecated libSass.[16]
  • phamlp, an unofficial Sass/SCSS implementation in PHP.[8]
  • Vaadin has a Java implementation of Sass.[17]
  • Firebug, a Firefox XUL ("legacy") extension for web development.[18] It has been since deprecated in favor of developer tools integrated into Firefox itself. It stopped working since Firefox 57 dropped support for XUL extensions.

Features

[edit]

Variables

[edit]

Sass allows variables to be defined. Variables begin with a dollar sign ($). Variable assignment is done with a colon (:).[18]

SassScript supports four data types:[18]

  • Numbers (including units)
  • Strings (with quotes or without)
  • Colors (name, or names)
  • Booleans

Variables can be arguments to or results from one of several available functions.[19] During translation, the values of the variables are inserted into the output CSS document.[2]

SCSS Sass Compiled CSS
$primary-color: #3bbfce;
$margin: 16px;

.content-navigation {
  border-color: $primary-color;
  color: darken($primary-color, 10%);
}

.border {
  padding: $margin / 2;
  margin: $margin / 2;
  border-color: $primary-color;
}
$primary-color: #3bbfce
$margin: 16px

.content-navigation
  border-color: $primary-color
  color: darken($primary-color, 10%)

.border
  padding: $margin/2
  margin:  $margin/2
  border-color: $primary-color
:root{
    --primary-color:#3bbfce;
    --secondary-color:#2b9eab;
    --margin:8px;
}


.content-navigation {
  border-color: var(--secondary-color)
  color: var(--secondary-color);
}

.border {
  padding: 8px;
  margin: var(--margin);
  border-color: #3bbfce;
}

Nesting

[edit]

CSS does support logical nesting, but the code blocks themselves are not nested. Sass allows the nested code to be inserted within each other.[2]

SCSS Sass Compiled CSS
table.hl {
  margin: 2em 0;
  td.ln {
    text-align: right;
  }
}

li {
  font: {
    family: serif;
    weight: bold;
    size: 1.3em;
  }
}
table.hl 
  margin: 2em 0
  td.ln 
    text-align: right
  
li 
  font: 
    family: serif
    weight: bold
    size: 1.3em
table.hl {
  margin: 2em 0;
}
table.hl td.ln {
  text-align: right;
}

li {
  font-family: serif;
  font-weight: bold;
  font-size: 1.3em;
}

More complicated types of nesting including namespace nesting and parent references are discussed in the Sass documentation.[18]

SCSS Sass Compiled CSS
@mixin table-base {
  th {
    text-align: center;
    font-weight: bold;
  }
  td, th {
    padding: 2px;
  }
}

#data {
  @include table-base;
}
=table-base
  th
    text-align: center
    font-weight: bold
  td, th
    padding: 2px

#data
  +table-base
#data th {
  text-align: center;
  font-weight: bold;
}
#data td, #data th {
  padding: 2px;
}

Loops

[edit]

Sass allows for iterating over variables using @for, @each and @while, which can be used to apply different styles to elements with similar classes or ids.

Sass Compiled CSS
$squareCount: 4
@for $i from 1 to $squareCount 
  #square-#{$i} 
   background-color: red
   width: 50px * $i
   height: 120px / $i
#square-1 {
  background-color: red;
  width: 50px;
  height: 120px;
}

#square-2 {
  background-color: red;
  width: 100px;
  height: 60px;
}

#square-3 {
  background-color: red;
  width: 150px;
  height: 40px;
}

Arguments

[edit]

Mixins also support arguments.[2]

Sass Compiled CSS
=left($dist) 
  float: left
  margin-left: $dist

#data 
  +left(10px)
#data {
  float: left;
  margin-left: 10px;
}

In combination

[edit]
Sass Compiled CSS
=table-base
  th
    text-align: center
    font-weight: bold
  td, th 
    padding: 2px

=left($dist) 
  float: left
  margin-left: $dist

#data 
  +left(10px)
  +table-base
#data {
  float: left;
  margin-left: 10px;
}
#data th {
  text-align: center;
  font-weight: bold;
}
#data td, #data th {
  padding: 2px;
}

Selector inheritance

[edit]

While CSS3 supports the Document Object Model (DOM) hierarchy, it does not allow selector inheritance. In Sass, inheritance is achieved by inserting a line inside of a code block that uses the @extend keyword and references another selector. The extended selector's attributes are applied to the calling selector.[2]

Sass Compiled CSS
.error
  border: 1px #f00
  background: #fdd

.error.intrusion 
  font-size: 1.3em
  font-weight: bold

.badError 
  @extend .error
  border-width: 3px
.error, .badError {
  border: 1px #f00;
  background: #fdd;
}

.error.intrusion,
.badError.intrusion {
  font-size: 1.3em;
  font-weight: bold;
}

.badError {
  border-width: 3px;
}

Sass supports multiple inheritance.[18]

libSass

[edit]

At the 2012 HTML5 Developer Conference, Hampton Catlin, the creator of Sass, announced version 1.0 of libSass, an open source C++ implementation of Sass developed by Catlin, Aaron Leung, and the engineering team at Moovweb.[20][21]

According to Catlin, libSass can be "drop[ped] into anything and it will have Sass in it...You could drop it right into Firefox today and build Firefox and it will compile in there. We wrote our own parser from scratch to make sure that would be possible."[22]

The design goals of libSass are:

  • Performance – Developers have reported 10x speed up increases over the Ruby implementation of Sass.[23]
  • Easier integration – libSass makes it easier to integrate Sass into more software. Before libSass, tightly integrating Sass into a language or software product required bundling the entire Ruby interpreter. By contrast, libSass is a statically linkable library with zero external dependencies and C-like interface, making it easy to wrap Sass directly into other programming languages and tools. For example, open source libSass bindings now exist for Node, Go, and Ruby.[21]
  • Compatibility – libSass's goal is full compatibility with the official Ruby implementation of Sass. This goal has been achieved on libsass 3.3.[24]

IDE integration

[edit]
IDE integration of Sass
IDE Software
Adobe Dreamweaver CC 2017
Eclipse
Emacs sass-mode
JetBrains IntelliJ IDEA (Ultimate Edition)
JetBrains PhpStorm
JetBrains RubyMine
JetBrains WebStorm
Microsoft Visual Studio Mindscape
Microsoft Visual Studio SassyStudio
Microsoft WebMatrix
NetBeans
Vim haml.zip
Atom
Visual Studio Code
Sublime
Edit+

See also

[edit]

References

[edit]
  1. ^ a b "Dart Sass - latest release". github.com.
  2. ^ a b c d e f Media Mark (3.2.12). "Sass - Syntactically Awesome Stylesheets". Sass-lang.com. Retrieved 2014-02-23.{{cite web}}: CS1 maint: numeric names: authors list (link)
  3. ^ a b Firtman, Maximiliano (2013-03-15). Programming the Mobile Web. O'Reilly Media, Inc. ISBN 978-1-4493-3497-0.
  4. ^ Libby, Alex (2019). Introducing Dart Sass: A Practical Introduction to the Replacement for Sass, Built on Dart. Berkeley, CA: Apress. doi:10.1007/978-1-4842-4372-5. ISBN 978-1-4842-4371-8.
  5. ^ Sass - Syntactically Awesome Stylesheets Archived 2013-10-09 at the Wayback Machine Tutorial
  6. ^ "Sass: Syntactically Awesome Style Sheets". sass-lang.com. Archived from the original on 2013-09-01.
  7. ^ "Natalie Weizenbaum's blog". Archived from the original on 2007-10-11.
  8. ^ a b c "Sass / Scss". Drupal.org. 2009-10-21. Archived from the original on 2016-03-10. Retrieved 2014-02-23.
  9. ^ "sass". www.npmjs.com.
  10. ^ "sass-embedded". www.npmjs.com.
  11. ^ Weizenbaum, Natalie. "Ruby Sass Has Reached End-Of-Life « Sass Blog". sass.logdown.com. Retrieved 2019-04-21.
  12. ^ "Sass: Ruby Sass". sass-lang.com. Retrieved 2019-04-21.
  13. ^ "LibSass is Deprecated". sass-lang.com. 26 October 2020.
  14. ^ "node-sass". www.npmjs.com.
  15. ^ "jsass - A Java implementation of the Sass compiler (and some other goodies). - Google Project Hosting". Retrieved 2014-02-23.
  16. ^ "JSass documentation". jsass.readthedocs.io.
  17. ^ "SassCompiler (Vaadin 7.0.7 API)". Vaadin.com. 2013-06-06. Archived from the original on 2014-04-21. Retrieved 2014-02-23.
  18. ^ a b c d e Sass (Syntactically Awesome StyleSheets) SASS_REFERENCE
  19. ^ Module: Sass::Script::Functions Sass Functions
  20. ^ H. Catlin (2012-10-15). "Hampton's 6 Rules of Mobile Design". HTML5 Developer Conference. Archived from the original on 2021-12-15. Retrieved 2013-07-11.
  21. ^ a b M. Catlin (2012-04-30). "libsass". Moovweb Blog. Archived from the original on 2013-05-08. Retrieved 2013-07-11.
  22. ^ A. Stacoviak & A. Thorp (2013-06-26). "Sass, libsass, Haml and more with Hampton Catlin". Archived from the original on 2013-08-06. Retrieved 2013-07-30.
  23. ^ D. Le Nouaille (2013-06-07). "Sassc and Bourbon". Retrieved 2013-07-11.
  24. ^ "Sass Compatibility". sass-compatibility.github.io. Archived from the original on 2019-12-05. Retrieved 2019-11-29.

Further reading

[edit]
[edit]