Professional Documents
Culture Documents
2020
1st edition
By John Bach
SASS
INTRODUCTION
QUICK SETUP
VARIABLES
PARTIALS
NESTING
MIXINS + ARGUMENTS
FUNCTIONS
FEATURES
SYNTAX
CHAPTER I
NESTED RULES
REFERENCING PARENT SELECTORS USING THE & SYMBOL
NESTED PROPERTIES
PLACEHOLDER SELECTORS:% FOO
CHAPTER II
COMMENTS IN SASS
CHAPTER III
SASSSCRIPT FORMULATION
INTERACTIVE SHELL
VARIABLES: $
DATA TYPES
TEXT STRINGS
LISTS
SQUARE BRACKETS
MAPS
COLORS
FIRST CLASS FUNCTIONS
OPERATIONS
OPERATIONS ON NUMEROLOGY
DIVISION AND COEFFICIENT /
SUBTRACTION, NEGATIVE NUMBERS, AND COEFFICIENTS -
COLOR OPERATIONS
STRING OPERATIONS
BOOLEAN OPERATIONS
LIST OPERATIONS
PARENTHESES
FUNCTIONS
NAMED MEDIA (KEYWORD ARGUMENTS)
INTERPOLATION: # {}
SYMBOL & IN SASSSCRIPT
VARIABLES DEFAULT VALUE:! DEFAULT
CHAPTER IV
SASS / @ RULES
@IMPORT RULE
FRAGMENTS (PARTIALS)
@IMPORT MANIFOLD RULE
FAQ @MEDIA
@EXTEND RULE
HOW THE RULE WORKS @EXTEND
EXTENDING COMPOUND PARAMETERS
MULTIPLE EXTENDS
CHAINING EXTENDS
SELECTOR SEQUENCES
MERGING SELECTOR SEQUENCES
EXPANSION SELECTORS (@ EXTEND-ONLY SELECTORS)
ENSIGN! OPTIONAL
USE @EXTEND INSIDE THE INSTRUCTIONS
INSTRUCTION @ AT-ROOT
THE RULE @ AT-ROOT (WITHOUT: ...) AND THE RULE @ AT-ROOT (WITH: ...)
@DEBUG INSTRUCTION
INSTRUCTION @WARN
@ERROR
CHAPTER V
()
IF
@IF
@FOR
@EACH
MULTIPLE ASSIGNMENT
@WHILE
CHAPTER VI
MIXTURES IN SASS
CHAPTER VII
CHAPTER VIII
SASS EXPANSION
CHAPTER X
SASS FUNCTIONS
DECLARE ()
RANDOM_NUMBER_GENERATOR ()
RANDOM_SEED ()
SIGNATURE ()
ABS ()
ADJUST_COLOR ()
ADJUST_HUE ()
ALPHA ()
APPEND ()
BLUE ()
CALL ()
CEIL ()
CHANGE_COLOR ()
COMPARABLE ()
COMPLEMENT ()
CONTENT_EXISTS ()
COUNTER ()
COUNTERS ()
DARKEN ()
DESATURATE ()
FEATURE_EXISTS ()
FLOOR ()
FUNCTION_EXISTS ()
GET_FUNCTION ()
GLOBAL_VARIABLE_EXISTS ()
GRAYSCALE ()
GREEN ()
HSL ()
HSLA ()
HUE ()
IE_HEX_STR ()
IF ()
INDEX ()
INSPECT ()
INVERT ()
IS_BRACKETED ()
IS_SUPERSELECTOR ()
JOIN ()
KEYWORDS ()
LENGTH ()
LIGHTEN ()
LIGHTNESS ()
LIST_SEPARATOR ()
MAP_GET ()
MAP_HAS_KEY ()
MAP_KEYS ()
MAP_MERGE ()
MAP_REMOVE ()
MAP_VALUES ()
MAX ()
MIN ()
MIX ()
MIXIN_EXISTS ()
NTH ()
OPACIFY ()
OPACITY ()
PERCENTAGE ()
QUOTE ()
RANDOM ()
RED ()
RGB ()
RGBA ()
ROUND ()
SATURATE ()
SATURATION ()
SCALE_COLOR ()
SELECTOR_APPEND ()
SELECTOR_EXTEND ()
SELECTOR_NEST ()
SELECTOR_PARSE ()
SELECTOR_REPLACE ()
SELECTOR_UNIFY ()
SET_NTH ()
SIMPLE_SELECTORS ()
STR_INDEX ()
STR_INSERT ()
STR_LENGTH ()
STR_SLICE ()
TO_LOWER_CASE ()
TO_UPPER_CASE ()
TRANSPARENTIZE ()
TYPE_OF ()
UNIQUE_ID ()
UNIT ()
UNITLESS()
UNQUOTE ()
VARIABLE_EXISTS ()
ZIP ()
Introduction
Sass stands for Syntactically Awesome Stylesheets. Sass and is basically just
an extension to CSS that help us write more flexible styles.
Be aware that when we write in sass, browsers are not going to understand
our code, because it’s not CSS we’re writing, so we need to use a compiler to
compile our sass code to CSS.
* Hammer
* CodeKit
* Compass
* Koala
We’re not going to cover the whole process of installing and compiling sass
in this section. If you want to experiment and follow me through this book, I
suggest using an online editor such as Codepad or whatever you prefer,
without installing it on your machine.
A preprocessor like Sass or Less can help modularize your style sheets and
add a lot of useful functionality lacking in native CSS. It’s a lot easier to get
started than you might think, so here’s a quick overview of setup and
commonly used functions.
Quick setup
Check the specific install for your setup, but for a typical Node.js or React
project with styling within src folder, setup is as easy as running npm install -
-save node-sass-chokidar *bugfree wrapper for node-sass. Then in your
package.json add underscripts:
"scripts": {
"build-css": "node-sass-chokidar src/ -o src/",
"watch-css": "npm run build-css && node-sass-chokidar src/ -o src/ --watch --recursive",
change your .css files to .scss and run npm run watch-css and you’re good to
start DRYing up your CSS with the following:
Variables
Save any normal CSS value into a reusable variable, by adding $variable-
name:
$sky: skyblue;
$grass: lawngreen;header {
background-color: $sky;
}footer {
background-color: $grass;
}
A bonus feature with variables is their local scope within a CSS selectors, so
you can stop worrying about global namespace.
Partials
Mimicking HTML’s visually nested hierarchy that CSS lacks, you can nest
your styles within a parent for more clarity. Child selectors inherit styles from
their parent.
@import ‘variables';.container {
font-family: Arial, Helvetica, sans-serif; .child1 {
color: $sky;
font-size: 10px;
}
.child2 {
color: $grass;
font-size: 40px;
}}
Mixins + Arguments
Group common bundles of CSS declarations into a @mixin, then reuse them
throughout your files with @include. Optionally, you can add arguments and
default parameters, to help customize. A simple button for example:
Though you can roll your own functions with use of @mixin method above,
Sass comes with tons of prebuilt functions ready to use in any SCSS file. An
example of a few interesting ones:
Other key features of Sass are@function for creating your own functions and
control directives like @if, @for, @each, and @while to guide your function
logic. There are also tons of amazing libraries of mixins like bourbon,
breakpoint (for media queries), and buttons (for…buttons).
Features
There are two formats available for Sass technology. First, the syntax known
as SCSS (for Sassy CSS) that we will use in this documentation. This syntax
is an extension of the CSS language, meaning that every valid CSS file is an
automatically valid SCSS file without changing the meaning. In addition, the
SCSS syntax understands most of the CSS tricks and browser-specific
formats, such as the old filter feature of IE. This format is enhanced by the
Sass features shown below. The file extension using this format is scss.
The second syntax is old and is known as the indented syntax (or “Sass”
only), and provides a more concise way to write CSS by using the offset
instead of the curly brackets to denote bifurcation and selectors, and new
lines instead of the semicolon to separate the properties. Some people find
this easier to read and faster to write than SCSS. The displacement wording
has the same advantages as the SCSS wording although some of it is
formulated in a slightly different way, and this is explained in the reference to
the oblique wording. The file extension for using this format is sass.
Both formats can import files written to the other, and files can be
automatically converted from one of the two formats to the other using the
sass-convert command-line tool:
Note that this command does not create CSS files. For that, use the Sass
command, which we will explain elsewhere.
Chapter I
CSS extensions in Sass
Nested Rules
Sass allows CSS rules to bifurcate within each other and in this case the
internal rule is applied only within the external specifier it contains (outer
rule's selector). For example, see the following code:
#main p {
color: # 00ff00;
width: 97%;
.redbox {
background-color: # ff0000;
color: # 000000;
}
}
#main p {
color: # 00ff00;
width: 97%; }
#main p .redbox {
background-color: # ff0000;
color: # 000000; }
This helps avoid repeating parent selectors, and makes complicated CSS
layouts that contain a lot of manifold parameters simpler. For example, see
the following code:
#main {
width: 97%;
p, div {
font-size: 2em;
a {font-weight: bold; }
}
#main {
width: 97%; }
#main p, #main div {
font-size: 2em; }
#main p a, #main div a {
font-weight: bold; }
#main pre {
font-size: 3em; }
Referencing Parent Selectors using the & symbol
a{
font-weight: bold;
text-decoration: none;
&: hover {text-decoration: underline; }
body.firefox & {font-weight: normal; }
}
a{
font-weight: bold;
text-decoration: none; }
a: hover {
text-decoration: underline; }
body.firefox a {
font-weight: normal; }
The & symbol will be changed to the parent specifier as it appears in the CSS
lines. This means that if you have a deep branched rule (i.e. branched more
than one level), then the value of the parent parameter is fully recognized
before replacing the & character. For example, see the following code:
#main {
color: black;
a{
font-weight: bold;
&: hover {color: red; }
}
}
#main {
color: black; }
#main a {
font-weight: bold; }
#main a: hover {
color: red; }
In the case of compound selectors, they must appear & at the beginning, but
they can be followed by a suffix, which will be added to the parent
parameter. For example, see the following code:
#main {
color: black;
& -sidebar {border: 1px solid; }
}
You will be charged to:
#main {
color: black; }
# main-sidebar {
border: 1px solid; }
If a suffix cannot be applied to the parent specifier, Sass will launch an error.
Nested Properties
CSS has quite a few properties in namespaces; For example, the font-family,
font-size, and font-weight properties are all in the font namespace. In CSS, if
you want to set a set of features in the same domain name, you will have to
write it every time. Sass provides an abbreviation for this process, as it
suffices to write the namespace once and then put all of the sub-properties
within it. For example see the following code:
.funky {
font: {
family: fantasy;
size: 30em;
weight: bold;
}
}
.funky {
font-family: fantasy;
font-size: 30em;
font-weight: bold; }
The property propertypace itself can be given a value. See for example the
following:
.funky {
font: 20px / 24px fantasy {
weight: bold;
}
}
.funky {
font: 20px / 24px fantasy;
font-weight: bold;
}
Placeholder Selectors:% foo
Rules that use placeholders, without the @extend instruction, will not be
translated to CSS.
Chapter II
Comments in Sass
/ * This comment
* Its length is several lines.
* CSS when using the comments structure in
* It will appear in the exported file. * /
body {color: black; }
/ * This comment
* Its length is several lines.
* CSS when using the comments structure in
* It will appear in the exported file. * /
body {
color: black; }
a{
color: green; }
If the first character of a multi-line comment is!, This comment will always
be included in the CSS output even in compressed output modes. This is
useful if you want to add copyright notices to the resulting CSS file.
Multiline comments are inserted into the resulting CSS file after
interpolation. The following code explains this:
$ version: "1.2.3";
It can also be used to generate selectors and attribute names, which is useful
when writing mixins, as this is done using interpolation.
Interactive Shell
You can try SassScript easily with the interactive shell. To run this shell, type
the sass command on the command line followed by the -i option, then enter
in the prompt any valid expression in SassScript to evaluate it and print the
results.
$ sass -i
>> "Hello, Sassy World!"
Hello, Sassy World!
>> 1px + 1px + 1px
3px
>> # 777 + # 777
#eeeeee
>> # 777 + # 888
white
Variables: $
The intuitive way to use SassScript is to use variables. Variables begin with
the dollar sign ($), and are set as well as CSS properties.
$ width: 5em;
#main {
width: $ width;
}
Variables will be visible only at the level of the branched setting where they
are defined or not. If you are defined outside all of the complex specifiers,
they will be available everywhere. It can also be made available everywhere
manually by using the Flags! Global. See for example:
#main {
$ width: 5em! global;
width: $ width;
}
#sidebar {
width: $ width;
}
#main {
width: 5em;
}
#sidebar {
width: 5em;
}
SassScript also supports all other types of CSS property values, such as
Unicode encoding fields and declarations! Important. However, these types
are not treated specially, but are treated as unquoted text strings.
Text strings
In CSS there are two types of strings: cited text strings, such as 'Lucida
Grande' or 'http://sass-lang.com', and non-cited text strings, such as sans-serif
or bold. SassScript recognizes both types and will be the same type used in
the sass file and the resulting CSS file.
There is one exception to that rule: when you use interpolation {{# #}, the
strings of text quoted will not be quoted. This makes it easier to use mixins'
names. See for example:
Sass uses menus to represent CSS declaration values such as margin: 10px
15px 0 0 or font-face: Helvetica, Arial, sans-serif. Lists are only a series of
other values separated by either spaces or commas. In fact, single values are
lists as well as single lists.
Menus are of no use without the SassScript menu functions. For example, the
nth function can access the elements in the list, the join function includes
several lists together, and the append function adds elements to the lists; The
@each statement can add styles to every element in the list.
In addition to simple values, lists can contain other lists. For example, the
1px 2px, 5px 6px list is a binary list that contains the 1px 2px list and the 6px
5px list. If the internal lists use the same comma as the external list, the
parentheses should be used to indicate the beginning and end of the internal
list. For example, the list (1px 2px) (5px 6px) is a binary list that contains the
1px 2px list and the 5px 6px list. The difference is that the outer and inner list
are separated by white spaces, unlike the previous example where the outer is
separated by a comma and the interior is white.
When converting lists to CSS, sass does not add parentheses as CSS does not
recognize parentheses. This means that the list (1px 2px) (5px 6px) and the
list 1px 2px 5px 6px will look the same when they are compiled into CSS.
However, you will not be the same when writing them in sass, as the first is a
list that contains two lists, while the second is a list that contains four
numbers.
Lists can be empty of any element and are represented only by parentheses ()
(which can also mean a blank [map]). This type of list cannot appear directly
in the CSS output. If you try using font-family: () for example, then sass will
make a mistake. If a list contains an empty list or null such as 2px 1px () 3px
or 1px 2px null 3px, empty lists and numeric values will be removed before
converting them to CSS.
Lists can also be written using square brackets. Square bracketed lists are
used as line names in CSS network charts, but they can also be used in sass
code, just like any other list. Square brackets can be separated by white
spaces or commas.
Maps
Maps are a link between values called keys and other values. The keys are
used to find values and make it easier to group them into named groups and
to reach those groups dynamically. Maps have no direct equivalent in CSS,
although their wording is similar to media query expressions.
Maps are handled similarly to lists, using the SassScript functions. For
example, the map-get function looks for specific values on the map, and the
map-merge function adds values to the map. The @each instruction can be
used to add patterns to each key / value pair on the map. The order of pairs in
the map has not changed since its creation.
Maps can be used anywhere menus are used. When used by a menu function,
it will be treated as a list of pairs. List functions such as the map (key1:
value1, key2: value2) will be treated as the branched list key1 value1, key2
value2. Lists cannot be treated as maps except for the blank list. () Represents
a map that does not contain any pairs (key / value) and a list that does not
contain any elements at the same time.
It is worth noting that map keys can be any type of Sass data. The format
used to define the map allows the use of any SassScript expression that will
be evaluated and determined to identify the value of the key.
Maps cannot be translated to CSS as their use as variables or data for CSS
functions will cause an error. Use the inspect ($ value) function to produce a
text string when outputting maps in the resulting CSS file.
Colors
All color expressions in CSS return a color value in SassScript. This includes
a large number of named labels, which are indistinguishable from unquoted
text strings.
A common problem with using named colors is that since sass prefers the
same output format as it did in other output modes, interpolated colors in a
specific parameter will become invalid when compressed at that time. This
problem can be avoided by always putting named colors in double quotes if
you want to use them to create a marker.
First Class Functions
All types support equalization operators (== and =!). In addition, each type
supports its own parameters.
Operations on numerology
Comparative coefficients (<,>, = <, =>) are also supported by numbers, and
equalization coefficients (== and =!) Are supported by all types.
Division and Coefficient /
There are three cases in which the symbol / will be interpreted as a division.
These cases include most of the uses of the division process:
p{
font: 10px / 8px; // regular, not a CSS division
$ width: 1000px;
width: $ width / 2; // Using a variable, division occurs
width: round (1.5) / 2; // Using a function, division occurs
height: (500px / 2); // Using parentheses, division occurs
margin-left: 5px + 8px / 2px; // Use +, division occurs
font: (italic bold 10px / 8px); // Inside a list, parentheses are not counted
}
If you want to use variables while maintaining the regular formatting of the
parameter / in CSS, you can use the {} # interpolation to insert it directly. For
example, see the code:
p{
$ font-size: 12px;
$ line-height: 30px;
font: # {$ font-size} / # {$ line-height};
}
p{
font: 12px / 30px; }
Subtraction, negative numbers, and coefficients -
The parameter - can represent several different things in CSS and Sass. It can
be a minus operator (as in 5px - 3px), or the beginning of a negative number
(as in -3px), or it can be a single negative negation operator (such as - $ var),
and it can be part of an identifier (Such as font-weight). In most cases, the
function of the symbol can be known from the context, and some other cases
may be confused. Here are these recommendations as a general rule:
Always put a white space before and after labs when using to subtract.
Place a space before - but not after in the case of negative numbers or
single negation.
Put a single negative in parentheses if it is in a space-separated list, such as
10px (- $ var).
Being part of an identifier. That is, a-1 is an unquoted text string with the
value of "a-1", and units are excluded only. Sass usually allows any valid
identifier to be used as an identifier, but it may not be correct for identifiers to
contain a condition followed by a number. That is, 5px-3px is like 5px-3px.
The presence of two numbers without a white space indicates a
subtraction, so expression 1-2 is exactly the same as expression 1-2.
It exists before a number but is unprecedented by a number indicating that
that number is a negative number, so the term 1 -2 is a list containing 1 and
-2.
Its presence between two numbers regardless of the existence of spaces
indicates the subtraction process, so the expression 1 - $ var is the same as
the expression 1 - $ var.
Its presence before a certain value means that it is a single negation factor.
In other words, the negative value of the number is returned when it was
before it.
Color Operations
p{
color: # 010203 + # 040506;
}
p{
color: # 050709; }
p{
color: # 010203 * 2;
}
p{
color: # 020406; }
Colors with an alpha channel (that is, created by one of the rgba and hsla
functions) must have the same transparency value in order to perform the
arithmetic operations on them. These processes do not affect the value of
transparency. See for example:
p{
color: rgba (255, 0, 0, 0.75) + rgba (0, 255, 0, 0.75);
}
p{
color: rgba (255, 255, 0, 0.75); }
The opacity of a channel can be adjusted for a specific color using the opacify
and transparentize functions. See the following example:
p{
color: rgba (255, 0, 0, 0.8);
background-color: rgba (255, 0, 0, 0.25); }
The filters feature in the IE browser requires all colors to include the
transparency channel, and to be exactly #AABBCCDD. You can easily
convert the color using the ie_hex_str function. See the following example:
div {
filter: progid: DXImageTransform.Microsoft.gradient (enabled =
'false', startColorstr = # FF00FF00, endColorstr = # 80FF0000);
}
String Operations
p{
cursor: e + -resize;
}
p{
cursor: e-resize; }
Note that if a quoted text string is added to a non-quoted one (i.e. the quoted
text string is to the left of the + sign), the result is a quoted text string.
Likewise, if an unquoted text string is added to a quoted one (the unquoted
text string to the left of the + sign), the result is an unquoted text string. For
example, see the following code:
p: before {
content: "Foo" + Bar;
font-family: sans- + "serif";
}
p: before {
content: "Foo Bar";
font-family: sans-serif; }
By default, if two values are placed next to each other, they will be combined
with one space. See, for example, the code:
p{
margin: 3px + 4px auto;
}
p{
margin: 7px auto; }
Interpolation ({} #) can be used within a text string to fill a dynamic value
inside a string, see for example the following code:
p: before {
content: "I ate # {5 + 10} pies!";
}
p: before {
content: "I ate 15 pies!"; }
p: before {
content: "I ate pies!"; }
Boolean Operations
SassScript supports the use of the and operator and the or not operator with
Boolean values.
List Operations
Lists do not support any special transactions, but are handled using list
functions.
Parentheses
Brackets can be used to arrange operations. For example, see the following
code:
p{
width: 1em + (2em * 3);
}
p{
width: 7em; }
Functions
There are many useful functions defined in SassScript that can be called
using the regular syntax of CSS functions.
p{
color: hsl (0, 100%, 50%);
}
p{
color: # ff0000; }
Refer to the Sass functions page for a complete list of available functions.
Named media (Keyword Arguments)
Sass functions can be called using explicitly named arguments. The example
above can be written as:
p{
color: hsl ($ hue: 0, $ saturation: 100%, $ lightness: 50%);
}
This format may be less concise, but it can make the style file's readability
easier. It will also allow functions to provide more flexible interfaces, and
pass many media without having to call them.
The named arguments can be passed in any order, and data with default
values can be deleted. Since the named arguments are the names of variables,
there is no difference between using the underscores _ and using the regular
hyphens -.
Interpolation: # {}
You can also use variables in the SassScript language for selectors and
attribute names using the {} # interpolation syntax.
$ name: foo;
$ attr: border;
p. # {$ name} {
# {$ attr} -color: blue;
}
p.foo {
border-color: blue; }
p{
$ font-size: 12px;
$ line-height: 30px;
font: # {$ font-size} / # {$ line-height};
}
Even if the parent parameter does not contain a comma or a distance, the
symbol value & will always have two levels of bifurcation, so that they can
be reached in a uniform way.
If there is no AP specifier, then the value & will be null. This means that you
can use it in a mixin to check for the presence of the parent parameter.
@mixin does-parent-exist {
@if & {
&: hover {
color: red;
}
} @else {
a{
color: red;
}
}
}
Variables default value:! Default
You can set a default value for the variable if it is not already set by adding
the banner! Default, track that value. This means that whenever you assign a
value to the variable, that value (the default) will not be assigned to it again.
If you do not assign a value to the variable, then its value will be the default
default value. See the following code for example:
#main {
content: $ content;
new-content: $ new_content;
}
#main {
content: "First content";
new-content: "First time reference"; }
The null value assigned to the variable is treated as an unlisted value, so the
default value will be assigned to it at that time.
$ content: null;
$ content: "Non-null content"! default;
#main {
content: $ content;
}
#main {
content: "Non-null content"; }
Chapter IV
Sass / @ rules
Sass supports all CSS rules that begin with the @ symbol, as well as other
Sass language called directives. These rules have different effects in Sass,
which we will discuss in a little while. See also control directives and mixin
directives.
@Import rule
Sass expands the usage of the @import rule for CSS to allow it to import
SCSS and Sass files. All imported SCSS and Sass files will be combined in
one CSS file. In addition, the variables defined in the imported files can be
used in the main file.
Sass searches for other Sass files in the current folder, and in the Sass files
folder in Rack, Rails, and Merb. Additional search folders can also be
specified using the: load_paths or --load-path option on the command line.
The rule @import takes the name of the file to import. By default, you search
for a Sass file to import directly, but there are some circumstances that cause
it to drain into the @import rule for CSS:
If none of the above conditions is met and the file extension is .scss or .sass,
then the specified Sass file or SCSS file will be imported. If there is no
extension, Sass will try to find a file according to the given name, whether it
is .scss or .sass to import it. See the following example:
@import "foo.scss";
or:
@import "foo";
@import "foo.css";
@import "foo" screen;
@import "http://foo.com/bar";
@import url (foo);
@import "foo.css";
@import "foo" screen;
@import "http://foo.com/bar";
@import url (foo);
Multiple files can also be imported simultaneously using the @import rule.
For example see the following code:
The rounded-corners file and the text-shadow file will be imported. The
import statement may contain (# {}) but with some restrictions as it is not
possible to import a Sass file dynamically using variables; Compliance is
only valid for CSS imports. As such, it only works with url () imports. For
example see the following code:
$ family: unquote ("Droid + Sans");
@import url ("http://fonts.googleapis.com/css?family=#{$family}");
If you want to import a SCSS or Sass file without being compiled into a CSS
file, add an underscore to the beginning of the file name as this will tell Sass
not to translate it into a regular CSS file. You can then import those files
without using the underscore.
For example, if you have a _colors.scss file, a file named _colors.css will not
be created and you can execute the command:
@import "colors";
Although it is often useful to import files using @import at the top level of
the file, it is possible to import them using CSS rules and @media rules. Like
@import at the base-level @import, this includes the contents of the file
imported by @import. However, the imported rules will branch out in the
same location as the original @import rule.
For example, if example.scss contains:
.example {
color: red;
}
#main {
@import "example";
}
to me:
#main .example {
color: red;
}
Directives that are only allowed in the basic file level, such as @mixin or
@charset, may not be used in files imported via @import in forked context.
@Import may not be branched into mixins or control directives.
FAQ @media
@Media's instructions in Sass behave the same as you would in CSS with
one additional ability that it can bifurcate within CSS rules. If a @media
instruction appears within a CSS rule, it will be circulated up to the highest
level in the stylesheet, and all markers within its base will be placed inside
the rule. This will facilitate adding media-specific styles without having to
repeat the parameters or break the sequence of the styles file. For example,
see the following code:
.sidebar {
width: 300px;
@media screen and (orientation: landscape) {
width: 500px;
}
}
.sidebar {
width: 300px; }
@media screen and (orientation: landscape) {
.sidebar {
width: 500px; }}
@Media (@media queries) queries can also be branched into each other, and
the queries will then be aggregated using the and operator. For example, see
the code:
@media screen {
.sidebar {
@media (orientation: landscape) {
width: 500px;
}
}
}
$ media: screen;
$ feature: -webkit-min-device-pixel-ratio;
$ value: 1.5;
In some cases when designing a page, you may need a particular class to have
all the styles of another class in addition to its own styles. The most common
way to do this is with the absolute general class and the custom class
specified in the HTML code. For example, suppose we have one design for
normal errors and one for serious errors, To do this, we can write in the
following HTML file:
.error {
border: 1px # f00;
background-color: #fdd;
}
.seriousError {
border-width: 3px;
}
Unfortunately, this means that we must always remember to use the .error
parameter with .seriousError. This will be a maintenance burden and lead to
software defects that are difficult to detect and can negatively affect the
readability of the HTML file. The @extend instruction will avoid these
problems by telling Sass that one of the selectors will inherit the other's
patterns. For example, see the following code:
.error {
border: 1px # f00;
background-color: #fdd;
}
.seriousError {
@extend .error;
border-width: 3px;
}
.error, .seriousError {
border: 1px # f00;
background-color: #fdd;
}
.seriousError {
border-width: 3px;
}
This means that all of the patterns defined in the .error parameter will also be
applied to the .seriousError parameter in addition to its. In fact, all elements
of the .seriousError class are also elements of .error. Other rules that use
.error will also apply to .seriousError. For example, we assign patterns to
hacker errors such as:
.error.intrusion {
background-image: url ("/ image / hacked.png");
}
The @extend rule works by inserting the extended specifier (for example
.seriousError) everywhere in the style file where the extended specifier (such
as .error) appears. Accordingly, the previous example:
.error {
border: 1px # f00;
background-color: #fdd;
}
.error.intrusion {
background-image: url ("/ image / hacked.png");
}
.seriousError {
@extend .error;
border-width: 3px;
}
.error, .seriousError {
border: 1px # f00;
background-color: #fdd; }
.error.intrusion, .seriousError.intrusion {
background-image: url ("/ image / hacked.png"); }
.seriousError {
border-width: 3px; }
When merging the specifiers, the @extend rule is smart enough to avoid
unnecessary repetition, so the expression .seriousError.seriousError will be
translated to .seriousError. In addition, it will not produce markers that
cannot match anything, such as the # main # footer.
.
Extending compound parameters
Class selectors are not the only ones that can be expanded because any
parameter can expand only one element, such as .special.cool, a: hover, or
.user [href ^ = "http: //"]. See the following example:
.hoverlink {
@extend a: hover;
}
This means that all patterns defined for a: hover will be applied, as is the case
with the classes, also to the .hoverlink parameter. For example, you will run
the following code:
.hoverlink {
@extend a: hover;
}
a: hover {
text-decoration: underline;
}
to me:
a: hover, .hoverlink {
text-decoration: underline; }
As with the .error.intrusion parameter above, any rule that uses a: hover will
also work on .hoverlink even if it has other parameters. The following code:
.hoverlink {
@extend a: hover;
}
.comment a.user: hover {
font-weight: bold;
}
A single marker can expand multiple markers. This means that it will inherit
the patterns of all the parameters that are extended. For example, you will run
the following code:
.error {
border: 1px # f00;
background-color: #fdd;
}
.attention {
font-size: 3em;
background-color: # ff0;
}
.seriousError {
@extend .error;
@extend .attention;
border-width: 3px;
}
to me:
.error, .seriousError {
border: 1px # f00;
background-color: #fdd; }
.attention, .seriousError {
font-size: 3em;
background-color: # ff0; }
.seriousError {
border-width: 3px; }
In fact, every element of the .seriousError class will also be of the .error class
and .attention class and will then have priority over the styles defined last in
the file, meaning that the background color of the .seriousError parameter
will be # ff0 and not #fdd, because .Attention find out after .error.
.error {
border: 1px # f00;
background-color: #fdd;
}
.seriousError {
@extend .error;
border-width: 3px;
}
.criticalError {
@extend .seriousError;
position: fixed;
top: 10%;
bottom: 10%;
left: 10%;
right: 10%;
}
Anything with the .seriousError class will also have the .error class; And
everything with the .criticalError class will also have the .seriousError class
and the .error class, the example above will be categorized into:
.seriousError, .criticalError {
border-width: 3px; }
.criticalError {
position: fixed;
top: 10%;
bottom: 10%;
left: 10%;
right: 10%; }
Selector Sequences
# fake-links .link {
@extend a;
}
a{
color: blue;
&: hover {
text-decoration: underline;
}
}
to me:
a, # fake-links .link {
color: blue; }
a: hover, # fake-links .link: hover {
text-decoration: underline; }
Merging Selector Sequences
Sometimes successive markers expand a marker that appears in another
sequence marker. In this case, the following selectors must be combined,
such as:
#admin .tabbar a {
font-weight: bold;
}
#demo .overview .fakelink {
@extend a;
}
#admin .tabbar a {
font-weight: bold;
}
#demo .overview .fakelink {
@extend a;
}
Will be disbursed to:
#admin .tabbar a,
#admin .tabbar #demo .overview .fakelink,
#demo .overview #admin .tabbar .fakelink {
font-weight: bold; }
If the two successive parameters share some of the determinants, then those
determinants are combined with the differences being modified (if any). In
the following example, both successive parameters contain ID #admin, so the
resulting settings will combine these two identifiers:
#admin .tabbar a {
font-weight: bold;
}
#admin .overview .fakelink {
@extend a;
}
#admin .tabbar a,
#admin .tabbar .overview .fakelink,
#admin .overview .tabbar .fakelink {
font-weight: bold; }
Expansion selectors (@ extend-Only Selectors)
Sometimes you may need to write styles for only classes intended for
expansion, and you do not want to use them directly in the HTML code. This
is especially useful when you want to create a library for Sass, as it will then
provide patterns that users can extend if they like.
If you use regular classes for this, you'll end up creating a large CSS file with
the potential to overlap with other classes used in the HTML code. For this
reason, Sass supports placeholders selector (such as% foo).
Placeholders appear to be identifiers for classes and identifiers, except that
the symbols are # or. They are replaced by%. They can be used anywhere
classes or identifiers are used, and rulesets are not allowed to be included in a
CSS file. For example:
.notice {
@extend% extreme;
}
Will be disbursed to:
#context a.notice {
color: blue;
font-weight: bold;
font-size: 2em; }
Ensign! Optional
If the @extend rule does not work with a parameter expansion, an error is
usually raised. For example, if you type important {@extend .notice}, an
error will occur if there is no parameter containing .notice. An error will also
occur if the only parameter containing .notice is h1.notice, because h1
overlaps with element a, so no new parameter is created.
Sometimes you may want to allow the @extend rule not to produce any new
specification. To do so, it is enough to add the flag optional! After the
parameter such as:
a.important {
@extend .notice! optional;
}
Use @extend inside the instructions
There are some limitations to using @extend within instructions like @media
as Sass is unable to have CSS rules outside of the @media block apply to the
settings inside them without making the style file be inflated due to copying
existing styles. This means that if you use @extend inside @media (or other
CSS instructions), only the parameters that appear inside the same instruction
block will be expanded.
For example, the following code works well:
@media print {
.error {
border: 1px # f00;
background-color: #fdd;
}
.seriousError {
@extend .error;
border-width: 3px;
}
}
.error {
border: 1px # f00;
background-color: #fdd;
}
@media print {
.seriousError {
// INVALID EXTEND: .error is used outside of the "@media print"
directive
@extend .error;
border-width: 3px;
}
}
The @ at-root statement shifts one or more rules to the root level of the
document, preventing them from bifurcating within the parent parameters. It
can be used either with a single inline selector, such as:
.parent {
...
@ at-root .child {...}
}
.parent {...}
.child {...}
.parent {
...
@ at-root {
.child1 {...}
.child2 {...}
}
.step-child {...}
}
@media print {
.page {
width: 8in;
@ at-root (without: media) {
color: red;
}
}
}
It will produce:
@media print {
.page {
width: 8in;
}
}
.page {
color: red;
}
You can use @ at-root (without: ...) to exit any statement. You can also exit
several white space separated instructions such as @ at-root (without: media
supports) that will exit the parameter outside of the @media and @supports
queries.
You can pass two special values to @ at-root. "Rule" refers to regular CSS
rules, so @ at-root (without: rule) is the same as @ at-root without any query.
And @ at-root (without: all) means that patterns must be moved outside of all
CSS instructions and rules.
it will be:
Illustrative example:
@mixin adjust-location ($ x, $ y) {
@if unitless ($ x) {
@warn "Assuming # {$ x} to be in pixels";
$ x: 1px * $ x;
}
@if unitless ($ y) {
@warn "Assuming # {$ y} to be in pixels";
$ y: 1px * $ y;
}
position: relative; left: $ x; top: $ y;
}
@Error
@mixin adjust-location ($ x, $ y) {
@if unitless ($ x) {
@error "$ x may not be unitless, was # {$ x}.";
}
@if unitless ($ y) {
@error "$ y may not be unitless, was # {$ y}.";
}
position: relative; left: $ x; top: $ y;
}
Note: Control instructions are an advanced feature and are not very popular.
It was originally found to be used in mixins, especially those that are part of
libraries such as Compass, and therefore requires great flexibility in dealing
with them.
if ()
The @if directive takes an expression from SassScript expressions and uses
the subforms below it when the expression returns any value other than false
or null, such as:
p{
@if 1 + 1 == 2 {border: 1px solid; }
@if 5 <3 {border: 2px dotted; }
@if null {border: 3px double; }
}
p{
border: 1px solid; }
You can manually check $ var == false or $ var == null if you want to
distinguish between them. The @if instruction can be followed by several
instructions, such as the @else if instruction and the @else instruction, which
is used once at the end. If the @if instruction does not fulfill the condition, it
will go to the @else if instructions in order until one of them succeeds in
fulfilling the condition or the @else instruction will apply if the condition
does not meet any of them. See the following code:
$ type: monster;
p{
@if $ type == ocean {
color: blue;
} @else if $ type == matador {
color: red;
} @else if $ type == monster {
color: green;
} @else {
color: black;
}
}
p{
color: green; }
@For
The @for instruction is used to show a set of patterns repeatedly, and is used
at each frequency counter (variable) in order to set the number of patterns in
the patterns. There are two ways to use this instruction. The first is @for $
var from <start> through <end>, and the second is @for $ var from <start> to
<end>. The difference between them is in the words through and to, which
will define the frequency field, as will be explained. $ Var can be any
variable such as $ i and <start> and <end> are two SassScript expressions
that return whole numbers. When <start> is greater than <end>, the
countdown will be descending rather than ascending.
The @for parameter sets the variable $ var to the values in the specified field
sequentially each time you output the branched patterns using the value of $
var. Note that you will enter in the form from ... through the value <start> and
the value <end> in the field of counting, while you will not enter in the form
from ... to the value <end> i.e. the count will stop at the previous or
subsequent value according to the type of count (upward) Or descending).
The following example illustrates the use of the wording through:
.item-1 {
width: 2em; }
.item-2 {
width: 4em; }
.item-3 {
width: 6em; }
@Each
The regular form of the @each instruction is @each $ var in <list or map>. $
Var can be any variable, such as $ length or $ name, and <list or map> is an
SassScript expression that returns a list or map.
The @each statement gives the $ var variable all values in the list or map,
and then outputs the styles it contains using the value of $ var. See the
following example:
.puma-icon {
background-image: url ('/ images / puma.png'); }
.sea-slug-icon {
background-image: url ('/ images / sea-slug.png'); }
.egret-icon {
background-image: url ('/ images / egret.png'); }
.salamander-icon {
background-image: url ('/ images / salamander.png'); }
Multiple Assignment
@Each can use multiple variables, as in @each $ var1, $ var2, ... in <list>. If
<list> is a list consisting of several lists, then each of the sub-menu items will
be assigned to the corresponding variable such as:
.puma-icon {
background-image: url ('/ images / puma.png');
border: 2px solid black;
cursor: default; }
.sea-slug-icon {
background-image: url ('/ images / sea-slug.png');
border: 2px solid blue;
cursor: pointer; }
.egret-icon {
background-image: url ('/ images / egret.png');
border: 2px solid white;
cursor: move; }
h1 {
font-size: 2em; }
h2 {
font-size: 1.5em; }
h3 {
font-size: 1.2em; }
@While
$ i: 6;
@while $ i> 0 {
.item - # {$ i} {width: 2em * $ i; }
$ i: $ i - 2;
}
.item-6 {
width: 12em; }
.item-4 {
width: 8em; }
.item-2 {
width: 4em; }
Chapter VI
Mixtures in Sass
The mixtures allow the definition of patterns that can be reused in the
stylesheet without resorting to non-semantic items such as .float-left.
Mixtures can also contain all CSS rules and anything else permitted for use in
Sass files. Arguments can also be passed through, thus a wide range of
patterns can be produced with a small number of mixtures.
Defining a Mixin: @mixin
Mixins are defined by the @mixin instruction followed by the name of the
mixture, and it is optional to add media to it, then a block of patterns includes
the contents of the mixture. For example, the large-text mixture is defined as
follows:
@mixin large-text {
font: {
family: Arial;
size: 20px;
weight: bold;
}
color: # ff0000;
}
@mixin clearfix {
display: inline-block;
&: after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
* html & {height: 1px}
}
Mixture names (and all other Sass identifiers) can, for historical reasons,
contain hyphens and underscores without making a difference between them.
For example, if you define a mixture as add-column, you can also refer to it
as add_column, and vice versa.
Mixtures included: @include
Mixtures are included in the file via the @include instruction. This
instruction takes the name of a mixture and an optional medium, if any, and
includes patterns that the mixture defines in the current rule. For example, see
the following code:
.page-title {
@include large-text;
padding: 4px;
margin-top: 10px;
}
.page-title {
font-family: Arial;
font-size: 20px;
font-weight: bold;
color: # ff0000;
padding: 4px;
margin-top: 10px; }
Mixtures may also be inserted outside all the rules (i.e. at the root of the
document) as long as they do not directly define any properties or use any
parental indications such as:
@mixin silly-links {
a{
color: blue;
background-color: red;
}
}
@include silly-links;
a{
color: blue;
background-color: red; }
Other mixtures may be included when identifying the mixture, such as:
@mixin compound {
@include highlighted-background;
@include header-text;
}
Mixtures can take SassScript values as arguments that you pass to when
mixing a mixture, as they are available inside the mixture as variables.
When defining a mixture, the arguments are written as variable names
separated by commas and placed in parentheses after the name. Then the
values of those arguments are passed when the mixture is included in the
same way. See the following example:
p{
border-color: blue;
border-width: 1in;
border-style: dashed; }
Mixtures can also set media default values using the regular formula for
setting variables. If the medium is not passed then when mixing is included,
then this default value will be used. For example, see the following code:
@mixin beautiful-border ($ color, $ width: 1in) {
border: {
color: $ color;
width: $ width;
style: dashed;
}
}
p {@include beautiful-border (blue); }
h1 {@include beautiful-border (blue, 2in); }
p{
border-color: blue;
border-width: 1in;
border-style: dashed; }
h1 {
border-color: blue;
border-width: 2in;
border-style: dashed; }
Named media (Keyword Arguments)
Explicitly named media may also be used when mixtures are included. For
example, the previous example could be written as:
While this may be less succinct, it will make the stylesheet easier to read, and
will allow functions to offer more flexible interfaces to provide many media
without having to call it.
Named arguments can be passed in any order, and arguments with default
values may be deleted. Since the named arguments are the names of
variables, there is no difference between the use of regular dashes and the
dashes.
Trailing Commas
.shadows {
@include box-shadow (0px 4px 5px # 666, 2px 6px 10px # 999);
}
.shadows {
-moz-box-shadow: 0px 4px 5px # 666, 2px 6px 10px # 999;
-webkit-box-shadow: 0px 4px 5px # 666, 2px 6px 10px # 999;
box-shadow: 0px 4px 5px # 666, 2px 6px 10px # 999;
}
Variable arguments also contain all named arguments passed to the mixture
or function, and can be accessed using the keywords ($ args) function, which
returns them as maps, linking media names (without $) to their values.
Variable media can also be used when calling a mixture. You can use the
same format to expand a list of values so that each value is passed as a
separate medium, or to expand a map of values so that each pair is treated as
a named medium. For example, see the following code:
.primary {
color: # ff0000;
background-color: # 00ff00;
border-color: # 0000ff;
}
.secondary {
color: # 00ff00;
background-color: # 0000ff;
border-color: # ff0000;
}
You can pass a list and a map of the media at the same time, provided that the
list is passed before the map, such as @include colors ($ values ..., $ map ...).
You can use the variable media to wrap the mixture and add additional
patterns without changing the shape of the mixture media. If you do this, the
named media will be passed directly to the wrapped mixin such as:
.stylish {
// The broker will pass
// $ width
// As a medium to the mixture
// stylish-mixin
@include wrapped-stylish-mixin (# 00ff00, $ width: 100px);
}
Pass the style blocks to the mixture
@mixin apply-to-ie6-only {
* html {
@content;
}
}
@include apply-to-ie6-only {
#logo {
background-image: url (/logo.gif);
}
}
* html #logo {
background-image: url (/logo.gif);
}
The same mixtures can be created using the abbreviated form of .sass files,
such as:
= apply-to-ie6-only
* html
@content
+ apply-to-ie6-only
#logo
background-image: url (/logo.gif)
Note: When the @content instruction exists more than once or is used in a
loop, then the pattern block will be repeated at each call.
Some mixtures may require a mass of patterns to pass through, otherwise you
will behave differently. The content_exists () function will return TRUE if a
block of patterns is passed to the current mixture, and can be used to see the
behavior performed at that time.
Variable Scope and Content Blocks
$ color: white;
@mixin colors ($ color: blue) {
background-color: $ color;
@content;
border-color: $ color;
}
.colors {
@include colors {color: $ color; }
}
.colors {
background-color: blue;
color: white;
border-color: blue;
}
In addition, this makes it clear that the variables and mixtures used within the
block of passing patterns relate to other neighboring patterns where the block
is defined as:
#sidebar {
$ sidebar-width: 300px;
width: $ sidebar-width;
@include smartphone {
width: $ sidebar-width / 3;
}
}
Chapter VII
Sass function instructions
You can define your own functions in Sass and use them in any context or
any value within the program such as:
$ grid-width: 40px;
$ gutter-width: 10px;
@function grid-width ($ n) {
@return $ n * $ grid-width + ($ n - 1) * $ gutter-width;
}
#sidebar {
width: 240px; }
Note that functions can access all general variables and accept arguments as
mixins do. The function may contain many programmatic statements, and
@return must be called to return the function to a specified value. As in
mixtures, you can call functions defined in Sass using the named arguments.
In the above example, we can call the function in the following way:
Although the default style for CSS outputs in Sass is nice and reflects the
structure of the document, tastes and needs vary from person to person, so
Sass supports many other styles.
Sass allows you to choose between four different output modes by setting the
option: style or using the --style banner on the command line.
Note: Sass compiler that can be installed using the npm package manager
does not support the style: nested; If you want to use it, install the Sass code
as shown on the Sass setup, setup, and use page.
Bifurcated style nested
Hyperlink is the default Sass style, because it reflects the structure of your
CSS and HTML document patterns. Each characteristic in this pattern has its
own line, but the indentation is not fixed since each base is displaced based
on the depth of its branching. For example, see the following code:
#main {
color: #fff;
background-color: # 000; }
#main p {
width: 10em; }
.huge {
font-size: 10em;
font-weight: bold;
text-decoration: underline; }
Hyper Style is very useful when reading large CSS files, as it makes it easier
for you to understand the file structure without actually reading anything.
Expanded style
Expanded mode is normal and more similar to regular CSS, with each
characteristic taking a single line. Attributes are immersed within the rules,
but the rules are not displaced in any other way. See the following example:
#main {
color: #fff;
background-color: # 000;
}
#main p {
width: 10em;
}
.huge {
font-size: 10em;
font-weight: bold;
text-decoration: underline;
}
Compact style
The compressed style takes the lowest possible amount of space, and there
are no white spaces except for it necessary to separate the parameters in
addition to a new line at the end of the file. It also includes some other
secondary compression techniques such as choosing the smallest possible
color representation. This style is not supposed to be readable by other users.
For example, see the following code:
Users can define their own Sass functions using Ruby API. See for more
information Documenting functions.
Cache stores
Sass temporarily stores parsed documents so that they can be reused without
re-analyzing them unless changes occur to the file. By default, Sass will write
these temporary stored files to a location in the file system referenced in:
cache_location. If you are not able to write to the file system or need to share
the stored copy between system processes and Ruby operations, then you can
define your own cache store and set the option: cache_store. If you want
more information about creating a temporary store, please see the source
documentation.
Custom Importers
Sass Imports are responsible for taking the paths passed to @import and
creating the appropriate Sass code for those paths. By default, this code is
loaded from the file system, but imports can be made from a specific database
or via the HTTP protocol, or they can be made to use a different file system
naming than expected in Sass.
When questioning the value of @import, Sass will search upload paths for an
importer who has successfully imported the path. When one is found, the
imported file is used.
1 declare ()
2 random_number_generator ()
3 random_seed ()
4 signature ()
5 abs ()
6 adjust_color ()
7 adjust_hue ()
8 alpha ()
9 append ()
10 blue ()
11 call ()
12 ceil ()
13 change_color ()
14 comparable ()
15 complement ()
16 content_exists ()
17 counter ()
18 counters ()
19 darken ()
20 desaturate ()
21 feature_exists ()
22 floor ()
23 function_exists ()
24 get_function ()
25 global_variable_exists ()
26 grayscale ()
27 green ()
28 hsl ()
29 hsla ()
30 hue ()
31 ie_hex_str ()
32 if ()
33 index ()
34 inspect ()
35 invert ()
36 is_bracketed ()
37 is_superselector ()
38 join ()
39 keywords ()
40 length ()
41 lighten ()
42 lightness ()
43 list_separator ()
44 map_get ()
45 map_has_key ()
46 map_keys ()
47 map_merge ()
48 map_remove ()
49 map_values ()
50 max ()
51 min ()
52 mix ()
53 mixin_exists ()
54 nth ()
55 opacify ()
56 opacity ()
57 percentage ()
58 quote ()
59 random ()
60 red ()
61 rgb ()
62 rgba ()
63 round ()
64 saturate ()
65 saturation ()
66 scale_color ()
67 selector_append ()
68 selector_extend ()
69 selector_nest ()
70 selector_parse ()
71 selector_replace ()
72 selector_unify ()
73 set_nth ()
74 simple_selectors ()
75 str_index ()
76 str_insert ()
77 str_length ()
78 str_slice ()
79 to_lower_case ()
80 to_upper_case ()
81 transparentize ()
82 type_of ()
83 unique_id ()
84 unit ()
85 unitless ()
86 unquote ()
87 variable_exists ()
88 zip()
declare ()
Authorize a Sass signature for Ruby functions. The signature includes the
media names, will the function take a variable number of arguments, and
whether the function will accept a random set of named arguments.
random_number_generator ()
Determines the value of the seed used by Sass's internal random number
generator.
signature ()
Change the value of the hue component of the color it is passed to.
alpha ()
Returns the value of the alpha channel component for the color passed to it.
append ()
Returns the nearest integer greater than the number passed to it.
change_color ()
Change one or more of the properties of the given color: red, green, blue,
saturation, hue, and transparency.
comparable ()
This function exists only as an alternative to the content: counter issue in IE7.
It works similarly with any CSS function except that it avoids adding spaces
between media separators.
counters ()
This function exists only as an alternative to the content: counter issue in IE7.
It works similarly with any CSS function except that it avoids adding spaces
between media separators.
darken ()
Makes the color darker. Pass it a color and number between 0% and 100%,
then restore that color after reducing the brightness according to the last
value.
desaturate ()
Makes color less saturated. Pass it a color and number between 0% and 100%
and then return that color after reducing the value of its saturation component
according to the last value.
feature_exists ()
Returns a reference to a function for later call using the call () function.
global_variable_exists ()
Checks whether a variable is in the global scope, i.e. at the top level of the
file.
grayscale ()
Creates a new color based on the values of hue, saturation, and lightness.
hsla ()
Creates a color based on the values of hue, saturation, lightness, and alpha.
hue ()
Returns the value of the dye component to the color passed to.
ie_hex_str ()
Returns one of the two values passed to it, depending on whether a certain
condition is true. Just like the @if statement, all values are valid except false
and null.
index ()
Reposition an item in the list. If the element is not present, it will return the
null value.
inspect ()
Reverse the color passed to it. That is, the values of the red, green and blue
compounds reflect the color passed to them without affecting the opacity
value.
is_bracketed ()
Returns a map containing the named arguments passed to a function or mixin, which requires passing a
variable list of arguments.
length ()
Returns the length of the list you passed to. This function can also return the
number of pairs in a map.
lighten ()
It makes the color more light as it passes a color and number between 0% and
100% and then returns that color after increasing the brightness according to
the last value.
lightness ()
Returns the type of comma used to separate the list items that are passed to. If
the function does not find a comma because the list contains less than two
elements, it will return the value space.
map_get ()
Returns the value in the map associated with the given key. If the map does
not contain that key, the function returns the null value.
map_has_key ()
Checks if the map you pass to has a specific key and this key is related to a
value.
map_keys ()
Returns a list containing only the map keys you pass to.
map_merge ()
It restores a new map after deleting certain keys from the map it is passed to.
map_values ()
Returns a list that contains only the map values you pass to (without the
keys).
max ()
Returns the largest value in the set of numbers passed to. This function
accepts an unlimited number of parameters.
min ()
Returns the smallest value from a set of numbers passed to it. This function
accepts an unlimited number of parameters.
mix ()
Mix two colors, as they specify the average of each RGB component for both
colors to give the resulting color. Optionally, the mixing ratio can be
determined. Transparency is taken into account when adjusting and mixing
components according to their proportion.
mixin_exists ()
Returns the item with the position specified in the list it is passed to.
opacify ()
Makes (also called fade_in) more opacity. Pass it a color and number
between 0 and 1, then return that color after increasing its opacity according
to the last value.
opacity ()
Returns the opacity value of the color passed to it. Their value is usually
equal to 1, unless modified.
percentage ()
Quotation marks add to an unquoted text string. If the string is quoted, the
function will return it unchanged.
random ()
Creates a color based on passing the value of the three components: red,
green, and blue.
rgba ()
It returns a new parameter with all the $ selectors in the parameter being
added to each other as if it were branched in the stylesheet as $ selector1 {&
$ selector2 {...}}.
selector_extend ()
Returns a new parameter with all the selectors in the $ selectors parameter
branched together as if they were branched in the style file as $ selector1 {$
selector2 {...}}.
selector_parse ()
Two selectors unite in one selector that matches only identical elements in
both of these parameters. The function returns the null value if there is no
match between the two parameters.
set_nth ()
Returns a new list, based on the scrolled list, after replacing the value given
with the value of the $ n element.
simple_selectors ()
Returns the simple parameters that make up the composite parameter passed
to.
str_index ()
Returns the first occurrence of a specified text string within the given text
string.
str_insert ()
Returns a portion of the text string that you pass to and that begins and ends
at a specified position.
to_lower_case ()
The transparentize () function (also called fade_out) makes the color more
transparent. Pass it a color and number between 0 and 1, and then return that
color after lowering its opacity by the last value.
type_of ()
Returns the unit (or units) associated with the number passed to. The complex
units are arranged in alphabetical order, by numerator and denominator.
unitless ()
Removes quotes from the string you pass to. If that string is not quoted, the
function will return it unchanged.
variable_exists ()