digplanet beta 1: Athena
Share digplanet:

Agriculture

Applied sciences

Arts

Belief

Business

Chronology

Culture

Education

Environment

Geography

Health

History

Humanities

Language

Law

Life

Mathematics

Nature

People

Politics

Science

Society

Technology

Sass
Sass Logo.gif
Appeared in 2007
Designed by Hampton Catlin
Developer Nathan Weizenbaum, Chris Eppstein
Stable release 3.2.8 (May 11, 2013 (2013-05-11))
Typing discipline dynamic
Major implementations Ruby (programming language)
Influenced by CSS, Yaml, Haml
Influenced LESS, Stylus
OS Cross-platform
License MIT License
Usual filename extensions .sass, .scss

Sass (Syntactically Awesome Stylesheets) is a stylesheet language initially designed by Hampton Catlin and developed by Nathan Weizenbaum.[1][2] After its initial versions, Nathan Weizenbaum and Chris Eppstein have continued to extend Sass with SassScript, a simple scripting language used in Sass files.

Sass is a Cascading Style Sheets (CSS) metalanguage. It is a scripting language that is interpreted into 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.[3] It uses indentation to separate code blocks and newline characters to separate rules. The newer syntax, "SCSS", uses block formatting like that of CSS. It uses braces to denote code blocks and semicolons to separate lines within a block. The indented syntax and SCSS files are traditionally given the extensions .sass and .scss respectively.

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. Alternately, Sass can monitor the .sass or .scss file and translate it to an output .css file whenever the .sass or .scss file is saved.[4] Sass is simply syntactic sugar for CSS.

The official implementation of Sass is open-source and coded in Ruby, however, other implementations exist, including one in PHP for Drupal.[5] The indented syntax is a metalanguage. SCSS is a nested metalanguage, as valid CSS is valid SCSS with the same semantics. Sass supports integration with the Firefox extension Firebug.[6]

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

Contents

Variables [edit]

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

SassScript supports four data types:[6]

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

In SCSS style

$blue: #3bbfce;
$margin: 16px;

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

.border {
  padding: $margin / 2;
  margin: $margin / 2;
  border-color: $blue;
}

Or SASS style

$blue: #3bbfce
$margin: 16px

.content-navigation
  border-color: $blue
  color: darken($blue, 9%)

.border
  padding: $margin/2
  margin:  $margin/2
  border-color: $blue

Would compile to:

.content-navigation {
  border-color: #3bbfce;
  color: #2b9eab;
}
 
.border {
  padding: 8px;
  margin: 8px;
  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.[3]

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

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

Would compile to:

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.[6]

Mixins [edit]

CSS does not support mixins. Any repeated code must be repeated in each location. A mixin is a section of code that contains any valid Sass code. Whenever a mixin is called, the result of translating the mixin is inserted at the calling location. Mixins allow for efficient and clean code repetitions, as well as easy alteration of code.[3]

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

#data {
  @include table-base;
}

Would compile to:

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

Arguments [edit]

Mixins also support arguments.[3]

@mixin left($dist) {
  float: left;
  margin-left: $dist;
}

#data {
  @include left(10px);
}

Would compile to:

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

In combination [edit]

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

@mixin left($dist) {
  float: left;
  margin-left: $dist;
}

#data {
  @include left(10px);
  @include table-base;
}

Would compile to:

#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. Inheritance is done 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.[3]

.error {
  border: 1px #f00;
  background: #fdd;
}
.error.intrusion {
  font-size: 1.3em;
  font-weight: bold;
}

.badError {
  @extend .error;
  border-width: 3px;
}

Would compile to:

.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.[6]

IDE integration [edit]

IDE Software website
Microsoft Visual Studio Mindscape http://www.mindscapehq.com/products/web-workbench
Microsoft WebMatrix http://www.microsoft.com/web/
Eclipse
JetBrains RubyMine http://www.jetbrains.com/ruby/
JetBrains PhpStorm http://www.jetbrains.com/phpstorm/
NetBeans http://plugins.netbeans.org/plugin/34929/scss-support
Emacs SCSS Mode https://github.com/antonj/scss-mode/

See also [edit]

References [edit]

External links [edit]


Original courtesy of Wikipedia: http://en.wikipedia.org/wiki/Sass_(stylesheet_language) — Please support Wikipedia.
A portion of the proceeds from advertising on Digplanet goes to supporting Wikipedia.
1552 videos foundNext > 

DrupalCon Munich 2012: Preserving History for Future Generations: The King Center

There are few figures who have had as great an impact on the history of the last century as civil rights leader and social activist Dr. Martin Luther King, J...

GoGaRuCo 2011 - Sass: The Future of Stylesheets by Chris Eppstein

Golden Gate Ruby Conference 2011 Change video player: HTML5 / Flash Sass: The Future of Stylesheets Chris Eppstein Let's face it. CSS is dumb. There is no su...

Do More With LESS (and SASS) In Your CSS3 Stylesheets

Watch the full HD course: http://www.pluralsight-training.net/microsoft/courses/TableOfContents?courseName=better-css Bring the power of a dynamic language t...

Sass & Compass: Untangle your Stylesheets

Roy Tomeij, 80beans. In this session, Roy will cover the rationale behind Sass, syntax, new features and best practices. Writing CSS isn't fun. Repeating the...

Sam Richard and Mason Wendell at DrupalCon Portland

Nick Grace interviews these two senior front end developers from NBC universal about the merits of SASS, the systematically awesome stylesheet language. He a...

Organizing Your Stylesheets With Compass & Sass

Chris Eppstein, Caring.com. Are your stylesheets a mess? Do you find that changes to your CSS have unintended consequences? Sass & Compass give you a rich se...

Live Chat: Roy Tomeij on Untangling Your Stylesheets with Compass and Sass

Writing CSS isn't fun. Repeating the same selectors over and over, hand-crafting sprites and writing vendor prefixes make CSS the source of many headaches. S...

Day 30 - Ruby on Rails 3 - Syntactically Awesome Stylesheets (SASS) in Rails

How to start using SASS in your Rails project to create much more readable CSS with variables and "methods".

Installing and Using Sass

Sass is an extension of CSS3, adding nested rules, variables, mixins, selector inheritance, and more. It's translated to well-formatted, standard CSS using t...

Sass/SCSS und Compass - Stylesheets im Griff! - André Laugks beim MMT 29

Auf Grund der von Browsern unterstützen Standards wie beispielsweise CSS3, wird die Frontend-Entwicklung immer komplexer. Wie wäre es also, mit einem Framewo...

1552 videos foundNext > 

We're sorry, but there's no news about "Sass (stylesheet language)" right now.

Loading

Oops, we seem to be having trouble contacting Twitter

Talk About Sass (stylesheet language)

You can talk about Sass (stylesheet language) with people all over the world in our discussions.

Support Wikipedia

A portion of the proceeds from advertising on Digplanet goes to supporting Wikipedia. Please add your support for Wikipedia!