2009-06-18 13:40:57 -07:00
|
|
|
# Sass (Syntactically Awesome StyleSheets)
|
|
|
|
|
2009-06-18 14:56:02 -07:00
|
|
|
* Table of contents
|
|
|
|
{:toc}
|
|
|
|
|
2010-03-30 14:39:56 -07:00
|
|
|
Sass is an extension of CSS
|
|
|
|
that adds power and elegance to the basic language.
|
|
|
|
It allows you to use [variables](#variables_), [nested rules](#nested_rules),
|
|
|
|
[mixins](#mixins), [inline imports](#import), and more,
|
|
|
|
all with a fully CSS-compatible syntax.
|
|
|
|
Sass helps keep large stylesheets well-organized,
|
|
|
|
and get small stylesheets up and running quickly,
|
|
|
|
particularly with the help of
|
|
|
|
[the Compass style library](http://compass-style.org).
|
2009-06-18 13:40:57 -07:00
|
|
|
|
|
|
|
## Features
|
|
|
|
|
2010-03-30 14:39:56 -07:00
|
|
|
* Fully CSS3-compatible
|
|
|
|
* Language extensions such as variables, nesting, and mixins
|
|
|
|
* Many {Sass::Script::Functions useful functions} for manipulating colors and other values
|
|
|
|
* Advanced features like [control directives](#control_directives) for libraries
|
|
|
|
* Well-formatted, customizable output
|
|
|
|
* [Firebug integration](https://addons.mozilla.org/en-US/firefox/addon/103988)
|
|
|
|
|
|
|
|
## Syntax
|
|
|
|
|
|
|
|
There are two syntaxes available for Sass.
|
|
|
|
The first, known as SCSS (Sassy CSS) and used throughout this reference,
|
|
|
|
is an extension of the syntax of CSS3.
|
|
|
|
This means that every valid CSS3 stylesheet
|
|
|
|
is a valid SCSS file with the same meaning.
|
|
|
|
In addition, SCSS understands most CSS hacks
|
|
|
|
and vendor-specific syntax, such as [IE's old `filter` syntax](http://msdn.microsoft.com/en-us/library/ms533754%28VS.85%29.aspx).
|
|
|
|
This syntax is enhanced with the Sass features described below.
|
|
|
|
Files using this syntax have the `.scss` extension.
|
|
|
|
|
|
|
|
The second and older syntax, known as the indented syntax (or sometimes just "Sass"),
|
|
|
|
provides a more concise way of writing CSS.
|
|
|
|
It uses indentation rather than brackets to indicate nesting of selectors,
|
|
|
|
and newlines rather than semicolons to separate properties.
|
|
|
|
Some people find this to be easier to read and quicker to write than SCSS.
|
|
|
|
The indented syntax has all the same features,
|
|
|
|
although some of them have slightly different syntax;
|
|
|
|
this is described in {file:INDENTED_SYNTAX.md the indented syntax reference}.
|
|
|
|
Files using this syntax have the `.sass` extension.
|
|
|
|
|
|
|
|
Either syntax can [import](#import) files written in the other.
|
|
|
|
Files can be automatically converted from one syntax to the other
|
|
|
|
using the `sass-convert` command line tool:
|
|
|
|
|
|
|
|
# Convert Sass to SCSS
|
|
|
|
$ sass-convert style.sass style.scss
|
|
|
|
|
|
|
|
# Convert SCSS to Sass
|
|
|
|
$ sass-convert style.scss style.sass
|
2009-06-18 13:40:57 -07:00
|
|
|
|
|
|
|
## Using Sass
|
|
|
|
|
|
|
|
Sass can be used in three ways:
|
2009-06-19 02:37:26 -07:00
|
|
|
as a command-line tool,
|
2009-06-18 13:40:57 -07:00
|
|
|
as a standalone Ruby module,
|
2009-11-09 18:35:29 -08:00
|
|
|
and as a plugin for any Rack-enabled framework,
|
|
|
|
including Ruby on Rails and Merb.
|
2009-06-18 13:40:57 -07:00
|
|
|
Sass is bundled with Haml,
|
|
|
|
so if the Haml plugin or RubyGem is installed,
|
|
|
|
Sass will already be installed as a plugin or gem, respectively.
|
|
|
|
The first step for all of these is to install the Haml gem:
|
|
|
|
|
|
|
|
gem install haml
|
|
|
|
|
2010-03-30 15:20:16 -07:00
|
|
|
If you're using Windows,
|
|
|
|
you may need to [install Ruby](http://rubyinstaller.org/download.html) first.
|
|
|
|
|
2009-06-19 02:37:26 -07:00
|
|
|
To run Sass from the command line, just use
|
|
|
|
|
2010-03-30 15:20:16 -07:00
|
|
|
sass input.scss output.css
|
2009-06-19 02:37:26 -07:00
|
|
|
|
2010-03-30 14:48:34 -07:00
|
|
|
You can also tell Sass to watch the file and update the CSS
|
|
|
|
every time the Sass file changes:
|
|
|
|
|
2010-03-30 15:20:16 -07:00
|
|
|
sass --watch input.scss:output.css
|
2010-03-30 14:48:34 -07:00
|
|
|
|
|
|
|
If you have a directory with many Sass files,
|
|
|
|
you can also tell Sass to watch the entire directory:
|
|
|
|
|
|
|
|
sass --watch app/sass:public/stylesheets
|
|
|
|
|
2009-06-19 02:37:26 -07:00
|
|
|
Use `sass --help` for full documentation.
|
|
|
|
|
|
|
|
Using Sass in Ruby code is very simple.
|
|
|
|
After installing the Haml gem,
|
|
|
|
you can use it by running `require "sass"`
|
2010-03-30 15:20:16 -07:00
|
|
|
and using {Sass::Engine} like so:
|
2009-06-19 02:37:26 -07:00
|
|
|
|
2010-03-30 15:20:16 -07:00
|
|
|
engine = Sass::Engine.new("#main {background-color: #0000ff}", :syntax => :scss)
|
2009-06-19 02:37:26 -07:00
|
|
|
engine.render #=> "#main { background-color: #0000ff; }\n"
|
|
|
|
|
2009-11-09 18:35:29 -08:00
|
|
|
### Rack/Rails/Merb Plugin
|
2009-06-19 02:37:26 -07:00
|
|
|
|
|
|
|
To enable Sass as a Rails plugin, run
|
2009-06-18 13:40:57 -07:00
|
|
|
|
|
|
|
haml --rails path/to/rails/app
|
|
|
|
|
|
|
|
To enable Sass in Merb,
|
|
|
|
add
|
|
|
|
|
|
|
|
dependency "merb-haml"
|
|
|
|
|
2009-11-09 18:35:29 -08:00
|
|
|
to `config/dependencies.rb`.
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2009-11-09 18:35:29 -08:00
|
|
|
To enable Sass in a Rack application,
|
|
|
|
add
|
|
|
|
|
|
|
|
require 'sass/plugin/rack'
|
|
|
|
use Sass::Plugin::Rack
|
|
|
|
|
|
|
|
to `config.ru`.
|
|
|
|
|
|
|
|
Sass stylesheets don't work the same as views.
|
|
|
|
They don't contain dynamic content,
|
|
|
|
so the CSS only needs to be generated when the Sass file has been updated.
|
2010-03-30 15:20:16 -07:00
|
|
|
By default, `.sass` and `.scss` files are placed in public/stylesheets/sass
|
2009-06-19 03:00:57 -07:00
|
|
|
(this can be customized with the [`:template_location`](#template_location-option) option).
|
2009-06-18 13:40:57 -07:00
|
|
|
Then, whenever necessary, they're compiled into corresponding CSS files in public/stylesheets.
|
2010-03-30 15:20:16 -07:00
|
|
|
For instance, public/stylesheets/sass/main.scss would be compiled to public/stylesheets/main.css.
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2009-06-19 02:34:07 -07:00
|
|
|
### Caching
|
|
|
|
|
|
|
|
By default, Sass caches compiled templates and [partials](#partials).
|
|
|
|
This dramatically speeds up re-compilation of large collections of Sass files,
|
|
|
|
and works best if the Sass templates are split up into separate files
|
|
|
|
that are all [`@import`](#import)ed into one large file.
|
|
|
|
|
|
|
|
Without a framework, Sass puts the cached templates in the `.sass-cache` directory.
|
|
|
|
In Rails and Merb, they go in `tmp/sass-cache`.
|
|
|
|
The directory can be customized with the [`:cache_location`](#cache_location-option) option.
|
|
|
|
If you don't want Sass to use caching at all,
|
|
|
|
set the [`:cache`](#cache-option) option to `false`.
|
|
|
|
|
2009-06-19 02:20:00 -07:00
|
|
|
### Options
|
|
|
|
|
|
|
|
Options can be set by setting the {Sass::Plugin#options Sass::Plugin.options} hash
|
2009-11-09 18:35:29 -08:00
|
|
|
in `environment.rb` in Rails or `config.ru` in Rack...
|
2009-06-19 02:20:00 -07:00
|
|
|
|
|
|
|
Sass::Plugin.options[:style] = :compact
|
|
|
|
|
|
|
|
...or by setting the `Merb::Plugin.config[:sass]` hash in `init.rb` in Merb...
|
|
|
|
|
|
|
|
Merb::Plugin.config[:sass][:style] = :compact
|
|
|
|
|
|
|
|
...or by passing an options hash to {Sass::Engine#initialize}.
|
2010-03-30 15:20:16 -07:00
|
|
|
All relevant options are also available via flags
|
|
|
|
to the `sass` command-line executable.
|
2009-06-19 02:20:00 -07:00
|
|
|
Available options are:
|
|
|
|
|
|
|
|
{#style-option} `:style`
|
|
|
|
: Sets the style of the CSS output.
|
2009-07-09 05:38:40 -07:00
|
|
|
See [Output Style](#output_style).
|
2009-06-19 02:20:00 -07:00
|
|
|
|
2010-03-30 15:20:16 -07:00
|
|
|
{#syntax-option} `:syntax`
|
|
|
|
: The syntax of the input file, `:sass` for the indented syntax
|
|
|
|
and `:scss` for the CSS-extension syntax.
|
|
|
|
This is only useful when you're constructing {Sass::Engine} instances yourself;
|
|
|
|
it's automatically set properly when using {Sass::Plugin}.
|
|
|
|
Defaults to `:sass`.
|
|
|
|
|
2009-06-19 03:33:03 -07:00
|
|
|
{#property_syntax-option} `:property_syntax`
|
2010-03-30 15:20:16 -07:00
|
|
|
: Forces indented-syntax documents to use one syntax for properties.
|
2009-06-19 02:20:00 -07:00
|
|
|
If the correct syntax isn't used, an error is thrown.
|
2009-06-19 03:01:20 -07:00
|
|
|
`:new` forces the use of a colon or equals sign
|
2009-06-19 03:33:03 -07:00
|
|
|
after the property name.
|
2009-06-19 02:20:00 -07:00
|
|
|
For example: `color: #0f3`
|
2010-03-28 03:45:33 -07:00
|
|
|
or `width: $main_width`.
|
2009-06-19 03:01:20 -07:00
|
|
|
`:old` forces the use of a colon
|
2009-06-19 03:33:03 -07:00
|
|
|
before the property name.
|
2009-06-19 03:01:20 -07:00
|
|
|
For example: `:color #0f3`
|
2010-03-28 03:45:33 -07:00
|
|
|
or `:width $main_width`.
|
2009-06-19 02:20:00 -07:00
|
|
|
By default, either syntax is valid.
|
2010-03-30 15:20:16 -07:00
|
|
|
This has no effect on SCSS documents.
|
2009-06-19 02:20:00 -07:00
|
|
|
|
2009-06-28 20:49:27 -07:00
|
|
|
{#cache-option} `:cache`
|
2009-06-19 02:20:00 -07:00
|
|
|
: Whether parsed Sass files should be cached,
|
|
|
|
allowing greater speed. Defaults to true.
|
|
|
|
|
|
|
|
{#never_update-option} `:never_update`
|
|
|
|
: Whether the CSS files should never be updated,
|
|
|
|
even if the template file changes.
|
|
|
|
Setting this to true may give small performance gains.
|
|
|
|
It always defaults to false.
|
2009-11-09 18:35:29 -08:00
|
|
|
Only has meaning within Rack, Ruby on Rails, or Merb.
|
2009-06-19 02:20:00 -07:00
|
|
|
|
|
|
|
{#always_update-option} `:always_update`
|
|
|
|
: Whether the CSS files should be updated every
|
|
|
|
time a controller is accessed,
|
|
|
|
as opposed to only when the template has been modified.
|
|
|
|
Defaults to false.
|
2010-03-30 15:20:16 -07:00
|
|
|
Only has meaning within Rack, Ruby on Rails, or Merb.
|
2009-06-19 02:20:00 -07:00
|
|
|
|
|
|
|
{#always_check-option} `:always_check`
|
|
|
|
: Whether a Sass template should be checked for updates every
|
|
|
|
time a controller is accessed,
|
2009-11-09 18:35:29 -08:00
|
|
|
as opposed to only when the server starts.
|
2009-06-19 02:20:00 -07:00
|
|
|
If a Sass template has been updated,
|
|
|
|
it will be recompiled and will overwrite the corresponding CSS file.
|
|
|
|
Defaults to false in production mode, true otherwise.
|
2009-11-09 18:35:29 -08:00
|
|
|
Only has meaning within Rack, Ruby on Rails, or Merb.
|
2009-06-19 02:20:00 -07:00
|
|
|
|
|
|
|
{#full_exception-option} `:full_exception`
|
|
|
|
: Whether an error in the Sass code
|
2009-12-24 12:00:46 -08:00
|
|
|
should cause Sass to provide a detailed description
|
|
|
|
within the generated CSS file.
|
|
|
|
If set to true, the error will be displayed
|
|
|
|
along with a line number and source snippet
|
|
|
|
both as a comment in the CSS file
|
|
|
|
and at the top of the page (in supported browsers).
|
|
|
|
Otherwise, an exception will be raised in the Ruby code.
|
2009-06-19 02:20:00 -07:00
|
|
|
Defaults to false in production mode, true otherwise.
|
2009-11-09 18:35:29 -08:00
|
|
|
Only has meaning within Rack, Ruby on Rails, or Merb.
|
2009-06-19 02:20:00 -07:00
|
|
|
|
2009-06-21 16:25:32 -07:00
|
|
|
{#template_location-option} `:template_location`
|
2010-01-12 21:46:30 -08:00
|
|
|
: A path to the root sass template directory for your application.
|
2009-06-19 02:20:00 -07:00
|
|
|
If a hash, `:css_location` is ignored and this option designates
|
2009-07-04 14:49:09 -07:00
|
|
|
a mapping between input and output directories.
|
2009-06-19 02:20:00 -07:00
|
|
|
May also be given a list of 2-element lists, instead of a hash.
|
2009-11-09 18:35:29 -08:00
|
|
|
Defaults to `css_location + "/sass"`.
|
|
|
|
Only has meaning within Rack, Ruby on Rails, or Merb.
|
|
|
|
Note that if multiple template locations are specified, all
|
2009-07-04 14:49:09 -07:00
|
|
|
of them are placed in the import path, allowing you to import
|
|
|
|
between them.
|
2009-06-19 02:20:00 -07:00
|
|
|
|
2009-06-21 16:25:32 -07:00
|
|
|
{#css_location-option} `:css_location`
|
2009-06-19 02:20:00 -07:00
|
|
|
: The path where CSS output should be written to.
|
|
|
|
This option is ignored when `:template_location` is a Hash.
|
2009-11-09 18:35:29 -08:00
|
|
|
Defaults to `"./public/stylesheets"`.
|
|
|
|
Only has meaning within Rack, Ruby on Rails, or Merb.
|
2009-07-14 23:19:10 -07:00
|
|
|
|
2009-06-19 02:20:00 -07:00
|
|
|
{#cache_location-option} `:cache_location`
|
|
|
|
: The path where the cached `sassc` files should be written to.
|
2009-11-09 18:35:29 -08:00
|
|
|
Defaults to `"./tmp/sass-cache"` in Rails and Merb,
|
|
|
|
or `"./.sass-cache"` otherwise.
|
2009-06-19 02:20:00 -07:00
|
|
|
|
2010-01-23 13:06:45 -08:00
|
|
|
{#unix_newlines-option} `:unix_newlines`
|
|
|
|
: If true, use Unix-style newlines when writing files.
|
|
|
|
Only has meaning on Windows, and only when Sass is writing the files
|
2010-03-30 15:20:16 -07:00
|
|
|
(in Rack, Rails, or Merb, when using {Sass::Plugin} directly,
|
|
|
|
or when using the command-line executable).
|
2010-01-23 13:06:45 -08:00
|
|
|
|
2009-06-19 02:20:00 -07:00
|
|
|
{#filename-option} `:filename`
|
|
|
|
: The filename of the file being rendered.
|
|
|
|
This is used solely for reporting errors,
|
2009-11-09 18:35:29 -08:00
|
|
|
and is automatically set when using Rack, Rails, or Merb.
|
2009-06-19 02:20:00 -07:00
|
|
|
|
2009-09-14 03:32:02 -07:00
|
|
|
{#line-option} `:line`
|
|
|
|
: The number of the first line of the Sass template.
|
|
|
|
Used for reporting line numbers for errors.
|
|
|
|
This is useful to set if the Sass template is embedded in a Ruby file.
|
|
|
|
|
2009-06-19 02:20:00 -07:00
|
|
|
{#load_paths-option} `:load_paths`
|
|
|
|
: An array of filesystem paths which should be searched
|
2009-06-19 02:34:07 -07:00
|
|
|
for Sass templates imported with the [`@import`](#import) directive.
|
2009-11-09 18:35:29 -08:00
|
|
|
This defaults to the working directory and, in Rack, Rails, or Merb,
|
2009-06-19 02:20:00 -07:00
|
|
|
whatever `:template_location` is.
|
|
|
|
|
|
|
|
{#line_numbers-option} `:line_numbers`
|
|
|
|
: When set to true, causes the line number and file
|
|
|
|
where a selector is defined to be emitted into the compiled CSS
|
2010-03-19 04:14:34 -07:00
|
|
|
as a comment. Useful for debugging, especially when using imports
|
2009-06-19 02:20:00 -07:00
|
|
|
and mixins.
|
2010-01-22 08:51:03 -08:00
|
|
|
This option may also be called `:line_comments`.
|
2010-03-19 04:14:34 -07:00
|
|
|
Automatically disabled when using the `:compressed` output style
|
|
|
|
or the `:debug_info` option.
|
|
|
|
|
|
|
|
{#debug_info-option} `:debug_info`
|
|
|
|
: When set to true, causes the line number and file
|
|
|
|
where a selector is defined to be emitted into the compiled CSS
|
|
|
|
in a format that can be understood by the browser.
|
2010-03-19 14:42:52 -07:00
|
|
|
Useful in conjunction with [the FireSass Firebug extension](https://addons.mozilla.org/en-US/firefox/addon/103988)
|
2010-03-19 04:14:34 -07:00
|
|
|
for displaying the Sass filename and line number.
|
|
|
|
Automatically disabled when using the `:compressed` output style.
|
2009-06-19 02:20:00 -07:00
|
|
|
|
2009-12-23 20:55:27 -08:00
|
|
|
{#custom-option} `:custom`
|
|
|
|
: An option that's available for individual applications to set
|
|
|
|
to make data available to {Sass::Script::Functions custom Sass functions}.
|
|
|
|
|
2010-03-29 19:34:08 -07:00
|
|
|
{#sass2-option} `:sass2`
|
|
|
|
: Parses the document using semantics closer to that of Sass v2.
|
|
|
|
Currently, this just means that strings in mixin arguments
|
|
|
|
are treated as though they were in [an `=` context](#sass-script-strings).
|
|
|
|
|
2010-03-30 15:20:16 -07:00
|
|
|
## CSS Extensions
|
2009-06-18 13:40:57 -07:00
|
|
|
|
|
|
|
### Nested Rules
|
|
|
|
|
2010-03-30 15:20:16 -07:00
|
|
|
Sass allows CSS rules to be nested within one another.
|
|
|
|
The inner rule then only applies within the outer rule's selector.
|
2009-06-18 13:40:57 -07:00
|
|
|
For example:
|
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
#main p {
|
|
|
|
color: #00ff00;
|
|
|
|
width: 97%;
|
|
|
|
|
|
|
|
.redbox {
|
|
|
|
background-color: #ff0000;
|
|
|
|
color: #000000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-18 13:40:57 -07:00
|
|
|
is compiled to:
|
|
|
|
|
|
|
|
#main p {
|
|
|
|
color: #00ff00;
|
|
|
|
width: 97%; }
|
|
|
|
#main p .redbox {
|
|
|
|
background-color: #ff0000;
|
|
|
|
color: #000000; }
|
|
|
|
|
2010-03-30 15:20:16 -07:00
|
|
|
This helps avoid repetition of parent selectors,
|
|
|
|
and makes complex CSS layouts with lots of nested selectors much simpler.
|
|
|
|
For example:
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
#main {
|
|
|
|
width: 97%;
|
|
|
|
|
|
|
|
p, div {
|
|
|
|
font-size: 2em;
|
|
|
|
a { font-weight: bold; }
|
|
|
|
}
|
|
|
|
|
|
|
|
pre { font-size: 3em; }
|
|
|
|
}
|
|
|
|
|
2009-06-18 13:40:57 -07:00
|
|
|
is compiled to:
|
|
|
|
|
|
|
|
#main {
|
|
|
|
width: 97%; }
|
|
|
|
#main p, #main div {
|
|
|
|
font-size: 2em; }
|
|
|
|
#main p a, #main div a {
|
|
|
|
font-weight: bold; }
|
|
|
|
#main pre {
|
|
|
|
font-size: 3em; }
|
|
|
|
|
2009-06-19 03:51:35 -07:00
|
|
|
### Referencing Parent Selectors: `&`
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-03-30 15:20:16 -07:00
|
|
|
Sometimes it's useful to use a nested rule's parent selector
|
|
|
|
in other ways than the default.
|
|
|
|
For instance, you might want to have special styles
|
|
|
|
for when that selector is hovered over
|
|
|
|
or for when the body element has a certain class.
|
|
|
|
In these cases, you can explicitly specify where the parent selector
|
|
|
|
should be inserted using the `&` character.
|
|
|
|
For example:
|
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
a {
|
|
|
|
font-weight: bold;
|
|
|
|
text-decoration: none;
|
|
|
|
&:hover { text-decoration: underline; }
|
2010-03-30 15:20:16 -07:00
|
|
|
body.firefox & { font-weight: normal; }
|
2010-01-02 18:41:31 -08:00
|
|
|
}
|
|
|
|
|
2010-03-30 15:20:16 -07:00
|
|
|
is compiled to:
|
2009-06-18 13:40:57 -07:00
|
|
|
|
|
|
|
a {
|
|
|
|
font-weight: bold;
|
|
|
|
text-decoration: none; }
|
|
|
|
a:hover {
|
|
|
|
text-decoration: underline; }
|
2010-03-30 15:20:16 -07:00
|
|
|
body.firefox a {
|
2009-06-18 13:40:57 -07:00
|
|
|
font-weight: normal; }
|
|
|
|
|
2010-03-30 15:20:16 -07:00
|
|
|
`&` will be replaced with the parent selector as it appears in the CSS.
|
|
|
|
This means that if you have a deeply nested rule,
|
|
|
|
the parent selector will be fully resolved
|
|
|
|
before the `&` is replaced.
|
|
|
|
For example:
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
#main {
|
2010-03-30 15:20:16 -07:00
|
|
|
color: black;
|
|
|
|
a {
|
|
|
|
font-weight: bold;
|
|
|
|
&:hover { color: red; }
|
2010-01-02 18:41:31 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-30 15:20:16 -07:00
|
|
|
is compiled to:
|
2009-06-18 13:40:57 -07:00
|
|
|
|
|
|
|
#main {
|
2010-03-30 15:20:16 -07:00
|
|
|
color: black; }
|
|
|
|
#main a {
|
|
|
|
font-weight: bold; }
|
|
|
|
#main a:hover {
|
|
|
|
color: red; }
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-03-30 15:20:16 -07:00
|
|
|
### Nested Properties
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2009-06-19 03:33:03 -07:00
|
|
|
CSS has quite a few properties that are in "namespaces;"
|
2009-06-18 13:40:57 -07:00
|
|
|
for instance, `font-family`, `font-size`, and `font-weight`
|
|
|
|
are all in the `font` namespace.
|
2009-06-19 03:33:03 -07:00
|
|
|
In CSS, if you want to set a bunch of properties in the same namespace,
|
2009-06-18 13:40:57 -07:00
|
|
|
you have to type it out each time.
|
2010-03-30 15:20:16 -07:00
|
|
|
Sass provides a shortcut for this:
|
2009-06-18 13:40:57 -07:00
|
|
|
just write the namespace one,
|
2010-03-30 15:20:16 -07:00
|
|
|
then nest each of the sub-properties within it.
|
2009-06-18 13:40:57 -07:00
|
|
|
For example:
|
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
.funky {
|
|
|
|
font: {
|
|
|
|
family: fantasy;
|
|
|
|
size: 30em;
|
|
|
|
weight: bold;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-18 13:40:57 -07:00
|
|
|
is compiled to:
|
|
|
|
|
|
|
|
.funky {
|
|
|
|
font-family: fantasy;
|
|
|
|
font-size: 30em;
|
|
|
|
font-weight: bold; }
|
|
|
|
|
2010-03-30 15:20:16 -07:00
|
|
|
The property namespace itself can also have a value.
|
2009-06-18 13:40:57 -07:00
|
|
|
For example:
|
|
|
|
|
2010-03-30 15:20:16 -07:00
|
|
|
.funky {
|
|
|
|
font: 2px/3px {
|
|
|
|
family: fantasy;
|
|
|
|
size: 30em;
|
|
|
|
weight: bold;
|
|
|
|
}
|
|
|
|
}
|
2009-06-18 13:40:57 -07:00
|
|
|
|
|
|
|
is compiled to:
|
|
|
|
|
2010-03-30 15:20:16 -07:00
|
|
|
.funky {
|
|
|
|
font: 2px/3px;
|
|
|
|
font-family: fantasy;
|
|
|
|
font-size: 30em;
|
|
|
|
font-weight: bold; }
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-03-29 13:22:02 -07:00
|
|
|
## SassScript {#sassscript}
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-03-28 03:45:33 -07:00
|
|
|
In addition to the plain CSS property syntax,
|
|
|
|
Sass supports a small set of extensions called SassScript.
|
|
|
|
SassScript allows properties to use
|
|
|
|
variables, arithmetic, and extra functions.
|
2010-03-30 15:26:40 -07:00
|
|
|
SassScript can be used in any property value.
|
|
|
|
|
2010-03-28 03:45:33 -07:00
|
|
|
SassScript can also be used to generate selectors and property names,
|
|
|
|
which is useful when writing [mixins](#mixins).
|
2010-03-30 15:26:40 -07:00
|
|
|
This is done via [interpolation](#interpolation_).
|
2009-06-19 03:20:48 -07:00
|
|
|
|
2009-06-18 13:40:57 -07:00
|
|
|
### Interactive Shell
|
|
|
|
|
|
|
|
You can easily experiment with SassScript using the interactive shell.
|
|
|
|
To launch the shell run the sass command-line with the `-i` option. At the
|
|
|
|
prompt, enter any legal SassScript expression to have it evaluated
|
|
|
|
and the result printed out for you:
|
|
|
|
|
|
|
|
$ sass -i
|
|
|
|
>> "Hello, Sassy World!"
|
|
|
|
"Hello, Sassy World!"
|
|
|
|
>> 1px + 1px + 1px
|
|
|
|
3px
|
|
|
|
>> #777 + #777
|
|
|
|
#eeeeee
|
|
|
|
>> #777 + #888
|
|
|
|
white
|
|
|
|
|
2010-03-30 14:39:56 -07:00
|
|
|
### Variables: `$` {#variables_}
|
2009-06-18 13:40:57 -07:00
|
|
|
|
|
|
|
The most straightforward way to use SassScript
|
2010-03-28 03:45:33 -07:00
|
|
|
is to use variables.
|
2010-03-06 18:27:36 -08:00
|
|
|
Variables begin with dollar signs,
|
2010-03-28 03:45:33 -07:00
|
|
|
and are set like CSS properties:
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-03-28 03:45:33 -07:00
|
|
|
$width: 5em;
|
2010-01-02 18:41:31 -08:00
|
|
|
|
2010-03-28 03:45:33 -07:00
|
|
|
You can then refer to them in properties:
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
#main {
|
2010-03-28 03:45:33 -07:00
|
|
|
width: $width;
|
2010-01-02 18:41:31 -08:00
|
|
|
}
|
|
|
|
|
2010-03-28 03:45:33 -07:00
|
|
|
Variables are only available within the level of nested selectors
|
2010-03-06 18:27:36 -08:00
|
|
|
where they're defined.
|
|
|
|
If they're defined outside of any nested selectors,
|
|
|
|
they're available everywhere.
|
|
|
|
|
|
|
|
Variables used to use the prefix character `!`;
|
|
|
|
this still works, but it's deprecated and prints a warning.
|
|
|
|
`$` is the recommended syntax.
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-03-29 13:22:02 -07:00
|
|
|
Variables also used to be defined with `=` rather than `:`;
|
|
|
|
this still works, but it's deprecated and prints a warning.
|
|
|
|
`:` is the recommended syntax.
|
|
|
|
|
2009-06-18 13:40:57 -07:00
|
|
|
### Data Types
|
|
|
|
|
2010-03-28 03:45:33 -07:00
|
|
|
SassScript supports four main data types:
|
2010-03-30 15:26:40 -07:00
|
|
|
|
2009-06-18 13:40:57 -07:00
|
|
|
* numbers (e.g. `1.2`, `13`, `10px`)
|
2010-03-28 03:45:33 -07:00
|
|
|
* strings of text, with and without quotes (e.g. `"foo"`, `'bar'`, `baz`)
|
2009-11-11 21:11:37 -08:00
|
|
|
* colors (e.g. `blue`, `#04a3f9`, `rgba(255, 0, 0, 0.5)`)
|
2009-06-18 13:40:57 -07:00
|
|
|
* booleans (e.g. `true`, `false`)
|
|
|
|
|
2010-03-28 03:45:33 -07:00
|
|
|
SassScript also supports all other types of CSS property value,
|
|
|
|
such as Unicode ranges and `!important` declarations.
|
|
|
|
However, it has no special handling for these types.
|
|
|
|
They're treated just like unquoted strings.
|
|
|
|
|
2010-03-29 19:34:08 -07:00
|
|
|
#### Strings {#sass-script-strings}
|
2010-03-28 03:45:33 -07:00
|
|
|
|
|
|
|
CSS specifies two kinds of strings: those with quotes,
|
|
|
|
such as `"Lucida Grande"` or `'http://sass-lang.com'`,
|
|
|
|
and those without quotes, such as `sans-serif` or `bold`.
|
|
|
|
SassScript recognizes both kinds,
|
|
|
|
and in general if one kind of string is used in the Sass document,
|
|
|
|
that kind of string will be used in the resulting CSS.
|
|
|
|
|
|
|
|
There is one exception to this, though:
|
|
|
|
when using [`#{}` interpolation](#interpolation_),
|
|
|
|
quoted strings are unquoted.
|
|
|
|
This makes it easier to use e.g. selector names in [mixins](#mixins).
|
|
|
|
For example:
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-03-28 03:45:33 -07:00
|
|
|
@mixin firefox-message($selector) {
|
|
|
|
body.firefox #{$selector}:before {
|
|
|
|
content: "Hi, Firefox users!"; } }
|
2010-01-02 18:41:31 -08:00
|
|
|
|
2010-03-28 03:45:33 -07:00
|
|
|
@include firefox-message(".header");
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-03-28 03:45:33 -07:00
|
|
|
is compiled to:
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-03-28 03:45:33 -07:00
|
|
|
body.firefox .header:before {
|
|
|
|
content: "Hi, Firefox users!"; }
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-03-29 13:22:02 -07:00
|
|
|
It's also worth noting that when using the [deprecated `=` property syntax](#sassscript),
|
|
|
|
all strings are interpreted as unquoted,
|
|
|
|
regardless of whether or not they're written with quotes.
|
|
|
|
|
2009-06-18 13:40:57 -07:00
|
|
|
### Operations
|
|
|
|
|
2010-03-28 03:45:33 -07:00
|
|
|
All types support equality operations (`==` and `!=`).
|
|
|
|
In addition, each type has its own operations
|
|
|
|
that it has special support for.
|
|
|
|
|
2009-11-11 21:11:37 -08:00
|
|
|
#### Number Operations
|
|
|
|
|
2009-06-18 13:40:57 -07:00
|
|
|
SassScript supports the standard arithmetic operations on numbers
|
|
|
|
(`+`, `-`, `*`, `/`, `%`),
|
|
|
|
and will automatically convert between units if it can:
|
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
p {
|
2010-03-28 03:45:33 -07:00
|
|
|
width: 1in + 8pt;
|
2010-01-02 18:41:31 -08:00
|
|
|
}
|
|
|
|
|
2009-06-18 13:40:57 -07:00
|
|
|
is compiled to:
|
|
|
|
|
|
|
|
p {
|
|
|
|
width: 1.111in; }
|
|
|
|
|
|
|
|
Relational operators
|
|
|
|
(`<`, `>`, `<=`, `>=`)
|
|
|
|
are also supported for numbers,
|
|
|
|
and equality operators
|
|
|
|
(`==`, `!=`)
|
|
|
|
are supported for all types.
|
|
|
|
|
2010-03-28 03:45:33 -07:00
|
|
|
##### Division and `/`
|
|
|
|
|
|
|
|
CSS allows `/` to appear in property values
|
|
|
|
as a way of separating numbers.
|
|
|
|
Since SassScript is an extension of the CSS property syntax,
|
|
|
|
it must support this, while also allowing `/` to be used for division.
|
|
|
|
This means that by default, if two numbers are separated by `/` in SassScript,
|
|
|
|
then they will appear that way in the resulting CSS.
|
|
|
|
|
|
|
|
However, there are three situations where the `/` will be interpreted as division.
|
|
|
|
These cover the vast majority of cases where division is actually used.
|
|
|
|
They are:
|
|
|
|
|
|
|
|
1. If the value, or any part of it, is stored in a variable.
|
|
|
|
2. If the value is surrounded by parentheses.
|
|
|
|
3. If the value is used as part of another arithmetic expression.
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
p {
|
2010-03-30 15:26:40 -07:00
|
|
|
font: 10px/8px; // Plain CSS, no division
|
2010-03-28 03:45:33 -07:00
|
|
|
$width: 1000px;
|
2010-03-30 15:26:40 -07:00
|
|
|
width: $width/2; // Uses a variable, does division
|
|
|
|
height: (500px/2); // Uses parentheses, does division
|
|
|
|
margin-left: 5px + 8px/2px; // Uses +, does division
|
|
|
|
}
|
2010-03-28 03:45:33 -07:00
|
|
|
|
|
|
|
is compiled to:
|
|
|
|
|
|
|
|
p {
|
|
|
|
font: 10px/8px;
|
|
|
|
width: 500px;
|
|
|
|
height: 250px;
|
|
|
|
margin-left: 9px; }
|
|
|
|
|
2009-11-11 21:11:37 -08:00
|
|
|
#### Color Operations
|
|
|
|
|
2009-07-09 08:48:03 -07:00
|
|
|
All arithmetic operations are supported for color values,
|
|
|
|
where they work piecewise.
|
|
|
|
This means that the operation is performed
|
|
|
|
on the red, green, and blue components in turn.
|
|
|
|
For example:
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
p {
|
2010-03-28 03:45:33 -07:00
|
|
|
color: #010203 + #040506;
|
2010-01-02 18:41:31 -08:00
|
|
|
}
|
|
|
|
|
2009-07-09 08:48:03 -07:00
|
|
|
computes `01 + 04 = 05`, `02 + 05 = 07`, and `03 + 06 = 09`,
|
|
|
|
and is compiled to:
|
2009-06-18 13:40:57 -07:00
|
|
|
|
|
|
|
p {
|
|
|
|
color: #050709; }
|
|
|
|
|
2010-03-28 03:45:33 -07:00
|
|
|
Often it's more useful to use {Sass::Script::Functions color functions}
|
|
|
|
than to try to use color arithmetic to achieve the same effect.
|
|
|
|
|
|
|
|
Arithmetic operations also work between numbers and colors,
|
2009-07-09 08:48:03 -07:00
|
|
|
also piecewise.
|
|
|
|
For example:
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
p {
|
2010-03-28 03:45:33 -07:00
|
|
|
color: #010203 * 2;
|
2010-01-02 18:41:31 -08:00
|
|
|
}
|
|
|
|
|
2009-07-09 08:48:03 -07:00
|
|
|
computes `01 * 2 = 02`, `02 * 2 = 04`, and `03 * 2 = 06`,
|
|
|
|
and is compiled to:
|
2009-06-18 13:40:57 -07:00
|
|
|
|
|
|
|
p {
|
|
|
|
color: #020406; }
|
|
|
|
|
2009-11-11 21:11:37 -08:00
|
|
|
Note that colors with an alpha channel
|
|
|
|
(those created with the {Sass::Script::Functions#rgba rgba}
|
|
|
|
or {Sass::Script::Functions#hsla hsla} functions)
|
|
|
|
must have the same alpha value in order for color arithmetic
|
|
|
|
to be done with them.
|
|
|
|
The arithmetic doesn't affect the alpha value.
|
|
|
|
For example:
|
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
p {
|
2010-03-28 03:45:33 -07:00
|
|
|
color: rgba(255, 0, 0, 0.75) + rgba(0, 255, 0, 0.75);
|
2010-01-02 18:41:31 -08:00
|
|
|
}
|
|
|
|
|
2009-11-11 21:11:37 -08:00
|
|
|
is compiled to:
|
|
|
|
|
|
|
|
p {
|
2010-03-30 15:26:40 -07:00
|
|
|
color: rgba(255, 255, 0, 0.75); }
|
2009-11-11 21:11:37 -08:00
|
|
|
|
|
|
|
The alpha channel of a color can be adjusted using the
|
|
|
|
{Sass::Script::Functions#opacify opacify} and
|
|
|
|
{Sass::Script::Functions#transparentize transparentize} functions.
|
|
|
|
For example:
|
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
$translucent-red: rgba(255, 0, 0, 0.5);
|
|
|
|
p {
|
|
|
|
color: opacify($translucent-red, 80%);
|
|
|
|
background-color: transparentize($translucent-red, 50%);
|
|
|
|
}
|
|
|
|
|
|
|
|
is compiled to:
|
|
|
|
|
|
|
|
p {
|
2010-03-30 15:26:40 -07:00
|
|
|
color: rgba(255, 0, 0, 0.9);
|
|
|
|
background-color: rgba(255, 0, 0, 0.25); }
|
2010-03-29 19:44:23 -07:00
|
|
|
|
|
|
|
#### String Operations
|
|
|
|
|
|
|
|
The `+` operation can be used to concatenate strings:
|
|
|
|
|
|
|
|
p {
|
|
|
|
cursor: e + -resize;
|
|
|
|
}
|
|
|
|
|
|
|
|
is compiled to:
|
|
|
|
|
|
|
|
p {
|
|
|
|
cursor: e-resize; }
|
|
|
|
|
|
|
|
Note that if a quoted string is added to an unquoted string
|
|
|
|
(that is, the quoted string is to the left of the `+`),
|
|
|
|
the result is a quoted string.
|
|
|
|
Likewise, if an unquoted string is added to a quoted string
|
|
|
|
(the unquoted string is to the left of the `+`),
|
|
|
|
the result is an unquoted string.
|
|
|
|
For example:
|
|
|
|
|
|
|
|
p:before {
|
|
|
|
content: "Foo " + Bar;
|
|
|
|
font-family: sans- + "serif"; }
|
|
|
|
|
|
|
|
is compiled to:
|
|
|
|
|
|
|
|
p:before {
|
|
|
|
content: "Foo Bar";
|
|
|
|
font-family: sans-serif; }
|
|
|
|
|
|
|
|
By default, if two values are placed next to one another,
|
|
|
|
they are concatenated with a space:
|
|
|
|
|
|
|
|
p {
|
|
|
|
margin: 3px + 4px auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
is compiled to:
|
|
|
|
|
|
|
|
p {
|
|
|
|
margin: 7px auto; }
|
|
|
|
|
|
|
|
Within a string of text, #{} style interpolation can be used to
|
|
|
|
place dynamic values within the string:
|
|
|
|
|
|
|
|
p:before {
|
|
|
|
content: "I ate #{5 + 10} pies!"; }
|
|
|
|
|
|
|
|
is compiled to:
|
|
|
|
|
|
|
|
p:before {
|
|
|
|
content: "I ate 15 pies!"; }
|
|
|
|
|
|
|
|
#### Boolean Operations
|
|
|
|
|
|
|
|
SassScript supports `and`, `or`, and `not` operators
|
|
|
|
for boolean values.
|
|
|
|
|
|
|
|
### Parentheses
|
|
|
|
|
|
|
|
Parentheses can be used to affect the order of operations:
|
|
|
|
|
|
|
|
p {
|
|
|
|
width: 1em + (2em * 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
is compiled to:
|
|
|
|
|
|
|
|
p {
|
|
|
|
width: 7em; }
|
|
|
|
|
|
|
|
### Functions
|
|
|
|
|
|
|
|
SassScript defines some useful functions
|
|
|
|
that are called using the normal CSS function syntax:
|
|
|
|
|
|
|
|
p {
|
|
|
|
color: hsl(0, 100%, 50%);
|
|
|
|
}
|
|
|
|
|
|
|
|
is compiled to:
|
|
|
|
|
|
|
|
#main {
|
|
|
|
color: #ff0000; }
|
|
|
|
|
|
|
|
See {Sass::Script::Functions} for a full listing of Sass functions,
|
|
|
|
as well as instructions on defining your own in Ruby.
|
|
|
|
|
|
|
|
### Interpolation: `#{}` {#interpolation_}
|
|
|
|
|
|
|
|
You can also use SassScript variables in selectors
|
|
|
|
and property names using #{} interpolation syntax:
|
|
|
|
|
|
|
|
$name: foo;
|
|
|
|
$attr: border;
|
|
|
|
p.#{$name} { #{$attr}-color: blue }
|
|
|
|
|
|
|
|
is compiled to:
|
|
|
|
|
|
|
|
p.foo {
|
|
|
|
border-color: blue; }
|
|
|
|
|
2010-03-29 23:11:07 -07:00
|
|
|
### Variable Defaults: `!default`
|
2010-03-29 19:44:23 -07:00
|
|
|
|
|
|
|
You can assign to variables if they aren't already assigned
|
2010-03-29 23:11:07 -07:00
|
|
|
by adding the `!default` flag to the end of the value.
|
|
|
|
This means that if the variable has already been assigned to,
|
|
|
|
it won't be re-assigned,
|
2010-03-29 19:44:23 -07:00
|
|
|
but if it doesn't have a value yet, it will be given one.
|
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
$content: "First content";
|
2010-03-29 23:11:07 -07:00
|
|
|
$content: "Second content?" !default;
|
|
|
|
$new_content: "First time reference" !default;
|
2010-03-29 19:44:23 -07:00
|
|
|
|
|
|
|
#main {
|
|
|
|
content: $content;
|
|
|
|
new-content: $new_content;
|
|
|
|
}
|
|
|
|
|
|
|
|
is compiled to:
|
|
|
|
|
|
|
|
#main {
|
|
|
|
content: First content;
|
|
|
|
new-content: First time reference; }
|
|
|
|
|
|
|
|
## Directives
|
|
|
|
|
|
|
|
Directives allow the author to directly issue instructions to the Sass compiler.
|
|
|
|
They're prefixed with an at sign, `@`,
|
|
|
|
followed by the name of the directive,
|
|
|
|
a space, and any arguments to it -
|
|
|
|
just like CSS directives.
|
|
|
|
For example:
|
|
|
|
|
|
|
|
{.sass-ex}
|
|
|
|
@import red.sass
|
|
|
|
|
|
|
|
{.scss-ex}
|
|
|
|
@import "red.sass";
|
|
|
|
|
|
|
|
Some directives can also control whether or how many times
|
|
|
|
a chunk of Sass is output.
|
|
|
|
Those are documented under Control Directives.
|
|
|
|
|
|
|
|
### `@import` {#import}
|
|
|
|
|
|
|
|
The `@import` directive works in a very similar way to the CSS import directive.
|
|
|
|
It can either compile to a literal CSS `@import` directive for a CSS file,
|
|
|
|
or it can import a Sass file.
|
|
|
|
If it imports a Sass file,
|
|
|
|
not only are the rules from that file included,
|
|
|
|
but all variables in that file are made available in the current file.
|
|
|
|
|
|
|
|
Sass looks for other Sass files in the working directory,
|
|
|
|
and the Sass file directory under Rack, Rails, or Merb.
|
|
|
|
Additional search directories may be specified
|
|
|
|
using the [`:load_paths`](#load_paths-option) option.
|
|
|
|
|
|
|
|
`@import` takes a filename with or without an extension.
|
|
|
|
If an extension isn't provided,
|
|
|
|
Sass will try to find a Sass file with the given basename in the load paths.
|
|
|
|
|
|
|
|
For example,
|
|
|
|
|
|
|
|
{.sass-ex}
|
|
|
|
@import foo.sass
|
|
|
|
|
|
|
|
{.scss-ex}
|
|
|
|
@import "foo.sass";
|
|
|
|
|
|
|
|
or
|
|
|
|
|
|
|
|
{.sass-ex}
|
|
|
|
@import foo
|
|
|
|
|
|
|
|
{.scss-ex}
|
|
|
|
@import "foo";
|
|
|
|
|
|
|
|
would compile to
|
|
|
|
|
|
|
|
.foo {
|
|
|
|
color: #f00; }
|
|
|
|
|
|
|
|
whereas
|
|
|
|
|
|
|
|
{.sass-ex}
|
|
|
|
@import foo.css
|
2009-11-11 21:11:37 -08:00
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.scss-ex}
|
2010-03-29 19:44:23 -07:00
|
|
|
@import "foo.css";
|
2010-01-02 18:41:31 -08:00
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
would compile to
|
2009-11-11 21:11:37 -08:00
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
@import "foo.css";
|
2009-11-11 21:11:37 -08:00
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
#### Partials {#partials}
|
2009-11-11 21:11:37 -08:00
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
If you have a Sass file that you want to import
|
|
|
|
but don't want to compile to a CSS file,
|
|
|
|
you can add an underscore to the beginning of the filename.
|
|
|
|
This will tell Sass not to compile it to a normal CSS file.
|
|
|
|
You can then refer to these files without using the underscore.
|
|
|
|
|
|
|
|
For example, you might have `_colors.sass`.
|
|
|
|
Then no `_colors.css` file would be created,
|
|
|
|
and you can do
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.sass-ex}
|
2010-03-29 19:44:23 -07:00
|
|
|
@import colors.sass
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.scss-ex}
|
2010-03-29 19:44:23 -07:00
|
|
|
@import colors.sass;
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
### `@debug`
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
The `@debug` directive prints the value of a SassScript expression
|
|
|
|
to standard error.
|
|
|
|
It's useful for debugging Sass files
|
|
|
|
that have complicated SassScript going on.
|
2010-03-28 03:45:33 -07:00
|
|
|
For example:
|
|
|
|
|
|
|
|
{.sass-ex}
|
2010-03-29 19:44:23 -07:00
|
|
|
@debug 10em + 12em
|
2010-03-28 03:45:33 -07:00
|
|
|
|
|
|
|
{.scss-ex}
|
2010-03-29 19:44:23 -07:00
|
|
|
@debug 10em + 12em;
|
2010-03-28 03:45:33 -07:00
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
outputs:
|
2010-03-28 03:45:33 -07:00
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
Line 1 DEBUG: 22em
|
2010-03-28 03:45:33 -07:00
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
### `@font-face`, `@media`, etc.
|
|
|
|
|
|
|
|
Sass behaves as you'd expect for normal CSS @-directives.
|
|
|
|
For example:
|
2009-07-09 08:48:03 -07:00
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.sass-ex}
|
2010-03-29 19:44:23 -07:00
|
|
|
@font-face
|
|
|
|
font-family: "Bitstream Vera Sans"
|
|
|
|
src: url(http://foo.bar/bvs)
|
2009-07-09 08:48:03 -07:00
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.scss-ex}
|
2010-03-29 19:44:23 -07:00
|
|
|
@font-face {
|
|
|
|
font-family: "Bitstream Vera Sans";
|
|
|
|
src: url(http://foo.bar/bvs");
|
2010-01-02 18:41:31 -08:00
|
|
|
}
|
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
compiles to:
|
2009-07-09 08:48:03 -07:00
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
@font-face {
|
|
|
|
font-family: "Bitstream Vera Sans";
|
|
|
|
src: url(http://foo.bar/bvs); }
|
2009-07-09 08:48:03 -07:00
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
and
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.sass-ex}
|
2010-03-29 19:44:23 -07:00
|
|
|
@media print
|
|
|
|
#sidebar
|
|
|
|
display: none
|
|
|
|
|
|
|
|
#main
|
|
|
|
background-color: white
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.scss-ex}
|
2010-03-29 19:44:23 -07:00
|
|
|
@media print {
|
|
|
|
#sidebar { display: none; }
|
2010-03-28 03:45:33 -07:00
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
#main { background-color: white; }
|
|
|
|
}
|
2010-03-28 03:45:33 -07:00
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
compiles to:
|
2010-03-28 03:45:33 -07:00
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
@media print {
|
|
|
|
#sidebar {
|
|
|
|
display: none; }
|
2010-01-02 18:41:31 -08:00
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
#main {
|
|
|
|
background-color: white; } }
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
## Control Directives
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
SassScript supports basic control directives for looping and conditional evaluation.
|
|
|
|
|
|
|
|
### `@if`
|
|
|
|
|
|
|
|
The `@if` statement takes a SassScript expression
|
|
|
|
and prints the code nested beneath it if the expression returns
|
|
|
|
anything other than `false`:
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.sass-ex}
|
2009-06-18 13:40:57 -07:00
|
|
|
p
|
2010-03-29 19:44:23 -07:00
|
|
|
@if 1 + 1 == 2
|
|
|
|
border: 1px solid
|
|
|
|
@if 5 < 3
|
|
|
|
border: 2px dotted
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.scss-ex}
|
|
|
|
p {
|
2010-03-29 19:44:23 -07:00
|
|
|
@if 1 + 1 == 2 { border: 1px solid; }
|
|
|
|
@if 5 < 3 { border: 2px dotted; }
|
2010-01-02 18:41:31 -08:00
|
|
|
}
|
|
|
|
|
2009-06-18 13:40:57 -07:00
|
|
|
is compiled to:
|
|
|
|
|
|
|
|
p {
|
2010-03-29 19:44:23 -07:00
|
|
|
border: 1px solid; }
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
The `@if` statement can be followed by several `@else if` statements
|
|
|
|
and one `@else` statement.
|
|
|
|
If the `@if` statement fails,
|
|
|
|
the `@else if` statements are tried in order
|
|
|
|
until one succeeds or the `@else` is reached.
|
|
|
|
For example:
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.sass-ex}
|
2010-03-29 19:44:23 -07:00
|
|
|
$type: monster
|
2009-06-18 13:40:57 -07:00
|
|
|
p
|
2010-03-29 19:44:23 -07:00
|
|
|
@if $type == ocean
|
|
|
|
color: blue
|
|
|
|
@else if $type == matador
|
|
|
|
color: red
|
|
|
|
@else if $type == monster
|
|
|
|
color: green
|
|
|
|
@else
|
|
|
|
color: black
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.scss-ex}
|
2010-03-29 19:44:23 -07:00
|
|
|
$type: monster;
|
2010-01-02 18:41:31 -08:00
|
|
|
p {
|
2010-03-29 19:44:23 -07:00
|
|
|
@if $type == ocean {
|
|
|
|
color: blue;
|
|
|
|
} @else if $type == matador {
|
|
|
|
color: red;
|
|
|
|
} @else if $type == monster {
|
|
|
|
color: green;
|
|
|
|
} @else {
|
|
|
|
color: black;
|
|
|
|
}
|
2010-01-02 18:41:31 -08:00
|
|
|
}
|
|
|
|
|
2009-06-18 13:40:57 -07:00
|
|
|
is compiled to:
|
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
p {
|
|
|
|
color: green; }
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
### `@for`
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
The `@for` statement has two forms:
|
|
|
|
`@for <var> from <start> to <end>` or
|
|
|
|
`@for <var> from <start> through <end>`.
|
|
|
|
`<var>` is a variable name, like `$i`,
|
|
|
|
and `<start>` and `<end>` are SassScript expressions
|
|
|
|
that should return integers.
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
The `@for` statement sets `<var>` to each number
|
|
|
|
from `<start>` to `<end>`,
|
|
|
|
including `<end>` if `through` is used.
|
|
|
|
For example:
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.sass-ex}
|
2010-03-29 19:44:23 -07:00
|
|
|
@for $i from 1 through 3
|
|
|
|
.item-#{$i}
|
|
|
|
width: 2em * $i
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.scss-ex}
|
2010-03-29 19:44:23 -07:00
|
|
|
@for $i from 1 through 3 {
|
|
|
|
.item-#{$i} { width: 2em * $i; }
|
|
|
|
}
|
2010-01-02 18:41:31 -08:00
|
|
|
|
2009-06-18 13:40:57 -07:00
|
|
|
is compiled to:
|
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
.item-1 {
|
|
|
|
width: 2em; }
|
|
|
|
.item-2 {
|
|
|
|
width: 4em; }
|
|
|
|
.item-3 {
|
|
|
|
width: 6em; }
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
### `@while`
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
The `@while` statement repeatedly loops over the nested
|
|
|
|
block until the statement evaluates to `false`. This can
|
|
|
|
be used to achieve more complex looping than the `@for`
|
|
|
|
statement is capable of.
|
2009-06-18 13:40:57 -07:00
|
|
|
For example:
|
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.sass-ex}
|
2010-03-29 19:44:23 -07:00
|
|
|
$i: 6
|
|
|
|
@while $i > 0
|
|
|
|
.item-#{$i}
|
|
|
|
width: 2em * $i
|
|
|
|
$i: $i - 2
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.scss-ex}
|
2010-03-29 19:44:23 -07:00
|
|
|
$i: 6;
|
|
|
|
@while $i > 0 {
|
|
|
|
.item-#{$i} { width: 2em * $i; }
|
|
|
|
$i: $i - 2;
|
2010-01-02 18:41:31 -08:00
|
|
|
}
|
|
|
|
|
2009-06-18 13:40:57 -07:00
|
|
|
is compiled to:
|
|
|
|
|
2010-03-29 19:44:23 -07:00
|
|
|
.item-6 {
|
|
|
|
width: 12em; }
|
|
|
|
|
|
|
|
.item-4 {
|
|
|
|
width: 8em; }
|
|
|
|
|
|
|
|
.item-2 {
|
|
|
|
width: 4em; }
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-03-28 03:45:33 -07:00
|
|
|
## Mixins {#mixins}
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2009-06-19 03:33:03 -07:00
|
|
|
Mixins enable you to define groups of CSS properties and
|
2009-06-18 13:40:57 -07:00
|
|
|
then include them inline in any number of selectors
|
|
|
|
throughout the document. This allows you to keep your
|
|
|
|
stylesheets DRY and also avoid placing presentation
|
|
|
|
classes in your markup.
|
|
|
|
|
2009-06-19 02:04:19 -07:00
|
|
|
### Defining a Mixin: `=`
|
2009-06-18 13:40:57 -07:00
|
|
|
|
|
|
|
To define a mixin you use a slightly modified form of selector syntax.
|
|
|
|
For example the `large-text` mixin is defined as follows:
|
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.sass-ex}
|
2009-06-18 13:40:57 -07:00
|
|
|
=large-text
|
2009-06-19 03:20:48 -07:00
|
|
|
font:
|
|
|
|
family: Arial
|
|
|
|
size: 20px
|
|
|
|
weight: bold
|
|
|
|
color: #ff0000
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.scss-ex}
|
|
|
|
@mixin large-text {
|
|
|
|
font: {
|
|
|
|
family: Arial;
|
|
|
|
size: 20px;
|
|
|
|
weight: bold;
|
|
|
|
}
|
|
|
|
color: #ff0000;
|
|
|
|
}
|
|
|
|
|
2009-06-18 13:40:57 -07:00
|
|
|
The initial `=` marks this as a mixin rather than a standard selector.
|
|
|
|
The CSS rules that follow won't be included until the mixin is referenced later on.
|
|
|
|
Anything you can put into a standard selector,
|
|
|
|
you can put into a mixin definition.
|
|
|
|
For example:
|
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.sass-ex}
|
2009-06-18 13:40:57 -07:00
|
|
|
=clearfix
|
|
|
|
display: inline-block
|
|
|
|
&:after
|
|
|
|
content: "."
|
|
|
|
display: block
|
|
|
|
height: 0
|
|
|
|
clear: both
|
|
|
|
visibility: hidden
|
|
|
|
* html &
|
|
|
|
height: 1px
|
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.scss-ex}
|
|
|
|
@mixin clearfix {
|
|
|
|
display: inline-block;
|
|
|
|
&:after {
|
|
|
|
content: ".";
|
|
|
|
display: block;
|
|
|
|
height: 0;
|
|
|
|
clear: both;
|
|
|
|
visibility: hidden;
|
|
|
|
}
|
|
|
|
* html & { height: 1px }
|
|
|
|
}
|
|
|
|
|
2009-06-19 02:04:19 -07:00
|
|
|
### Mixing It In: `+`
|
2009-06-18 13:40:57 -07:00
|
|
|
|
|
|
|
Inlining a defined mixin is simple,
|
|
|
|
just prepend a `+` symbol to the name of a mixin defined earlier in the document.
|
|
|
|
So to inline the `large-text` defined earlier,
|
|
|
|
we include the statment `+large-text` in our selector definition thus:
|
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.sass-ex}
|
2009-06-18 13:40:57 -07:00
|
|
|
.page-title
|
|
|
|
+large-text
|
2009-06-19 03:20:48 -07:00
|
|
|
padding: 4px
|
2010-01-02 18:41:31 -08:00
|
|
|
margin-top: 10px
|
|
|
|
|
|
|
|
{.scss-ex}
|
|
|
|
.page-title {
|
|
|
|
@include large-text;
|
|
|
|
padding: 4px;
|
|
|
|
margin-top: 10px;
|
|
|
|
}
|
2009-06-18 13:40:57 -07:00
|
|
|
|
|
|
|
This will produce the following CSS output:
|
|
|
|
|
|
|
|
.page-title {
|
|
|
|
font-family: Arial;
|
|
|
|
font-size: 20px;
|
|
|
|
font-weight: bold;
|
|
|
|
color: #ff0000;
|
|
|
|
padding: 4px;
|
|
|
|
margin-top: 10px; }
|
|
|
|
|
|
|
|
Any number of mixins may be defined and there is no limit on
|
|
|
|
the number that can be included in a particular selector.
|
|
|
|
|
|
|
|
Mixin definitions can also include references to other mixins.
|
|
|
|
For example:
|
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.sass-ex}
|
2009-06-18 13:40:57 -07:00
|
|
|
=compound
|
|
|
|
+highlighted-background
|
|
|
|
+header-text
|
|
|
|
|
|
|
|
=highlighted-background
|
2010-01-02 18:41:31 -08:00
|
|
|
background-color: #fc0
|
2009-06-18 13:40:57 -07:00
|
|
|
=header-text
|
2010-01-02 18:41:31 -08:00
|
|
|
font-size: 20px
|
|
|
|
|
|
|
|
{.scss-ex}
|
|
|
|
@mixin compound {
|
|
|
|
@include highlighted-background;
|
|
|
|
@include header-text;
|
|
|
|
}
|
|
|
|
|
|
|
|
@mixin highlighted-background {
|
|
|
|
background-color: #fc0;
|
|
|
|
}
|
|
|
|
@mixin header-text {
|
|
|
|
font-size: 20px;
|
|
|
|
}
|
2009-06-18 13:40:57 -07:00
|
|
|
|
|
|
|
Mixins that only define descendent selectors, can be safely mixed
|
|
|
|
into the top most level of a document.
|
|
|
|
|
|
|
|
### Arguments
|
|
|
|
|
|
|
|
Mixins can take arguments which can be used with SassScript:
|
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.sass-ex}
|
2010-03-06 16:13:29 -08:00
|
|
|
=sexy-border($color)
|
2009-06-19 03:20:48 -07:00
|
|
|
border:
|
2010-03-28 03:45:33 -07:00
|
|
|
color: $color
|
2009-06-19 03:20:48 -07:00
|
|
|
width: 1in
|
|
|
|
style: dashed
|
2009-06-18 13:40:57 -07:00
|
|
|
p
|
|
|
|
+sexy-border("blue")
|
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.scss-ex}
|
2010-03-06 16:13:29 -08:00
|
|
|
@mixin sexy-border($color) {
|
2010-01-02 18:41:31 -08:00
|
|
|
border: {
|
2010-03-28 03:45:33 -07:00
|
|
|
color: $color;
|
2010-01-02 18:41:31 -08:00
|
|
|
width: 1in;
|
|
|
|
style: dashed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p { @include sexy-border("blue"); }
|
|
|
|
|
2009-06-18 13:40:57 -07:00
|
|
|
is compiled to:
|
|
|
|
|
|
|
|
p {
|
|
|
|
border-color: #0000ff;
|
|
|
|
border-width: 1in;
|
|
|
|
border-style: dashed; }
|
|
|
|
|
|
|
|
Mixins can also specify default values for their arguments:
|
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.sass-ex}
|
2010-03-28 03:45:33 -07:00
|
|
|
=sexy-border($color, $width: 1in)
|
2009-06-19 03:20:48 -07:00
|
|
|
border:
|
2010-03-28 03:45:33 -07:00
|
|
|
color: $color
|
|
|
|
width: $width
|
2009-06-19 03:20:48 -07:00
|
|
|
style: dashed
|
2009-06-18 13:40:57 -07:00
|
|
|
p
|
|
|
|
+sexy-border("blue")
|
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.scss-ex}
|
2010-03-28 03:45:33 -07:00
|
|
|
@mixin sexy-border($color, $width: 1in) {
|
2010-01-02 18:41:31 -08:00
|
|
|
border: {
|
2010-03-28 03:45:33 -07:00
|
|
|
color: $color;
|
|
|
|
width: $width;
|
2010-01-02 18:41:31 -08:00
|
|
|
style: dashed;
|
|
|
|
}
|
|
|
|
p { @include sexy-border("blue"); }
|
|
|
|
|
2009-06-18 13:40:57 -07:00
|
|
|
is compiled to:
|
|
|
|
|
|
|
|
p {
|
|
|
|
border-color: #0000ff;
|
|
|
|
border-width: 1in;
|
|
|
|
border-style: dashed; }
|
|
|
|
|
|
|
|
## Comments
|
|
|
|
|
2009-06-19 02:04:19 -07:00
|
|
|
Sass supports two sorts of comments:
|
|
|
|
those that show up in the CSS output
|
|
|
|
and those that don't.
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2009-06-19 02:04:19 -07:00
|
|
|
### CSS Comments: `/*`
|
2009-06-18 13:40:57 -07:00
|
|
|
|
|
|
|
"Loud" comments are just as easy as silent ones.
|
|
|
|
These comments output to the document as CSS comments,
|
|
|
|
and thus use the same opening sequence: `/*`.
|
|
|
|
For example:
|
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.sass-ex}
|
2009-06-18 13:40:57 -07:00
|
|
|
/* A very awesome rule.
|
|
|
|
#awesome.rule
|
2009-06-19 03:33:03 -07:00
|
|
|
/* An equally awesome property.
|
2009-06-19 03:20:48 -07:00
|
|
|
awesomeness: very
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.scss-ex}
|
|
|
|
/* A very awesome rule. */
|
|
|
|
#awesome.rule {
|
|
|
|
/* An equally awesome property. */
|
|
|
|
awesomeness: very;
|
|
|
|
}
|
|
|
|
|
2009-06-18 13:40:57 -07:00
|
|
|
becomes
|
|
|
|
|
|
|
|
/* A very awesome rule. */
|
|
|
|
#awesome.rule {
|
2009-06-19 03:33:03 -07:00
|
|
|
/* An equally awesome property. */
|
2009-06-18 13:40:57 -07:00
|
|
|
awesomeness: very; }
|
|
|
|
|
|
|
|
You can also nest content beneath loud comments. For example:
|
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.sass-ex}
|
2009-06-18 13:40:57 -07:00
|
|
|
#pbj
|
|
|
|
/* This rule describes
|
|
|
|
the styling of the element
|
|
|
|
that represents
|
|
|
|
a peanut butter and jelly sandwich.
|
2009-06-19 03:20:48 -07:00
|
|
|
background-image: url(/images/pbj.png)
|
|
|
|
color: red
|
2009-06-18 13:40:57 -07:00
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.scss-ex}
|
|
|
|
#pbj {
|
|
|
|
/* This rule describes
|
|
|
|
the styling of the element
|
|
|
|
that represents
|
|
|
|
a peanut butter and jelly sandwich. */
|
|
|
|
background-image: url(/images/pbj.png);
|
|
|
|
color: red;
|
|
|
|
}
|
|
|
|
|
2009-06-18 13:40:57 -07:00
|
|
|
becomes
|
|
|
|
|
|
|
|
#pbj {
|
|
|
|
/* This rule describes
|
|
|
|
* the styling of the element
|
|
|
|
* that represents
|
|
|
|
* a peanut butter and jelly sandwich. */
|
|
|
|
background-image: url(/images/pbj.png);
|
|
|
|
color: red; }
|
|
|
|
|
2009-06-19 02:04:19 -07:00
|
|
|
### Sass Comments: `//`
|
|
|
|
|
|
|
|
It's simple to add "silent" comments,
|
|
|
|
which don't output anything to the CSS document,
|
|
|
|
to a Sass document.
|
|
|
|
Simply use the familiar C-style notation for a one-line comment, `//`,
|
|
|
|
at the normal indentation level and all text following it won't be output.
|
|
|
|
For example:
|
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.sass-ex}
|
2009-06-19 02:04:19 -07:00
|
|
|
// A very awesome rule.
|
|
|
|
#awesome.rule
|
2009-06-19 03:33:03 -07:00
|
|
|
// An equally awesome property.
|
2009-06-19 03:20:48 -07:00
|
|
|
awesomeness: very
|
2009-06-19 02:04:19 -07:00
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.scss-ex}
|
|
|
|
// A very awesome rule.
|
|
|
|
#awesome.rule {
|
|
|
|
// An equally awesome property.
|
|
|
|
awesomeness: very;
|
|
|
|
}
|
|
|
|
|
2009-06-19 02:04:19 -07:00
|
|
|
becomes
|
|
|
|
|
|
|
|
#awesome.rule {
|
|
|
|
awesomeness: very; }
|
|
|
|
|
|
|
|
You can also nest text beneath a comment to comment out a whole block.
|
|
|
|
For example:
|
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.sass-ex}
|
2009-06-19 02:04:19 -07:00
|
|
|
// A very awesome rule
|
|
|
|
#awesome.rule
|
2009-06-19 03:33:03 -07:00
|
|
|
// Don't use these properties
|
2009-06-19 02:04:19 -07:00
|
|
|
color: green
|
|
|
|
font-size: 10em
|
|
|
|
color: red
|
|
|
|
|
2010-01-02 18:41:31 -08:00
|
|
|
{.scss-ex}
|
|
|
|
// A very awesome rule
|
|
|
|
#awesome.rule {
|
|
|
|
// Don't use these properties
|
|
|
|
// color: green
|
|
|
|
// font-size: 10em
|
|
|
|
color: red;
|
|
|
|
}
|
|
|
|
|
2009-06-19 02:04:19 -07:00
|
|
|
becomes
|
|
|
|
|
|
|
|
#awesome.rule {
|
|
|
|
color: red; }
|
|
|
|
|
2009-06-18 13:40:57 -07:00
|
|
|
## Output Style
|
|
|
|
|
|
|
|
Although the default CSS style that Sass outputs is very nice,
|
|
|
|
and reflects the structure of the document in a similar way that Sass does,
|
|
|
|
sometimes it's good to have other formats available.
|
|
|
|
|
2009-06-28 20:49:27 -07:00
|
|
|
Sass allows you to choose between four different output styles
|
2009-06-18 13:40:57 -07:00
|
|
|
by setting the `:style` option.
|
2009-11-09 18:35:29 -08:00
|
|
|
In Rack, Rails, and Merb, this is done by setting `Sass::Plugin.options[:style]`;
|
|
|
|
otherwise, it's done by passing an options hash with `:style` set.
|
2009-06-18 13:40:57 -07:00
|
|
|
|
|
|
|
### `:nested`
|
|
|
|
|
|
|
|
Nested style is the default Sass style,
|
|
|
|
because it reflects the structure of the document
|
|
|
|
in much the same way Sass does.
|
2009-06-19 03:33:03 -07:00
|
|
|
Each property has its own line,
|
2009-06-18 13:40:57 -07:00
|
|
|
but the indentation isn't constant.
|
|
|
|
Each rule is indented based on how deeply it's nested.
|
|
|
|
For example:
|
|
|
|
|
|
|
|
#main {
|
|
|
|
color: #fff;
|
|
|
|
background-color: #000; }
|
|
|
|
#main p {
|
|
|
|
width: 10em; }
|
|
|
|
|
|
|
|
.huge {
|
|
|
|
font-size: 10em;
|
|
|
|
font-weight: bold;
|
|
|
|
text-decoration: underline; }
|
|
|
|
|
|
|
|
Nested style is very useful when looking at large CSS files
|
|
|
|
for the same reason Sass is useful for making them:
|
|
|
|
it allows you to very easily grasp the structure of the file
|
|
|
|
without actually reading anything.
|
|
|
|
|
|
|
|
### `:expanded`
|
|
|
|
|
|
|
|
Expanded is the typical human-made CSS style,
|
2009-06-19 03:33:03 -07:00
|
|
|
with each property and rule taking up one line.
|
|
|
|
Properties are indented within the rules,
|
2009-06-18 13:40:57 -07:00
|
|
|
but the rules aren't indented in any special way.
|
|
|
|
For example:
|
|
|
|
|
|
|
|
#main {
|
|
|
|
color: #fff;
|
|
|
|
background-color: #000;
|
|
|
|
}
|
|
|
|
#main p {
|
|
|
|
width: 10em;
|
|
|
|
}
|
|
|
|
|
|
|
|
.huge {
|
|
|
|
font-size: 10em;
|
|
|
|
font-weight: bold;
|
|
|
|
text-decoration: underline;
|
|
|
|
}
|
|
|
|
|
|
|
|
### `:compact`
|
|
|
|
|
|
|
|
Compact style, as the name would imply,
|
|
|
|
takes up less space than Nested or Expanded.
|
|
|
|
However, it's also harder to read.
|
|
|
|
Each CSS rule takes up only one line,
|
2009-06-19 03:33:03 -07:00
|
|
|
with every property defined on that line.
|
2009-06-18 13:40:57 -07:00
|
|
|
Nested rules are placed next to each other with no newline,
|
|
|
|
while groups of rules have newlines between them.
|
|
|
|
For example:
|
|
|
|
|
|
|
|
#main { color: #fff; background-color: #000; }
|
|
|
|
#main p { width: 10em; }
|
|
|
|
|
|
|
|
.huge { font-size: 10em; font-weight: bold; text-decoration: underline; }
|
|
|
|
|
|
|
|
### `:compressed`
|
|
|
|
|
|
|
|
Compressed style takes up the minimum amount of space possible,
|
|
|
|
having no whitespace except that necessary to separate selectors
|
|
|
|
and a newline at the end of the file.
|
|
|
|
It's not meant to be human-readable.
|
|
|
|
For example:
|
|
|
|
|
|
|
|
#main{color:#fff;background-color:#000}#main p{width:10em}.huge{font-size:10em;font-weight:bold;text-decoration:underline}
|