Menu

[r2]: / docs / variables.html  Maximize  Restore  History

Download this file

118 lines (102 with data), 4.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Variables: Switch</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link type="text/css" rel="stylesheet" title="Default Stylesheet" href="global.css" />
</head>
<body id="variables" class="documentation">
<div id="header">
</div>
<div id="localNav">
<h2>Switch</h2>
<ul id="extensionsNav">
<li><a href="install_mac.html">Installation (Mac)</a></li>
<li><a href="install_windows.html">Installation (Windows)</a></li>
<li><a href="variables.html">Variables</a></li>
<li><a href="constants.html">Constants</a></li>
<li><a href="includes.html">Includes</a></li>
<li><a href="comments.html">Comments</a></li>
<li><a href="ignore.html">Ignore</a>
<li><a href="auto_prepending.html">Automatic Selector Prepending</a></li>
<li><a href="inheritance.html">Inheritance</a></li>
<li><a href="copy.html">Property Duplication</a></li>
<li><a href="property_lookup.html">Property Look-ups</a></li>
</ul>
</div>
<div id="mainContent">
<h2>Variables: <code>$</code></h2>
<p>Authors can define variables in any object and use them anywhere one or more primitive values are expected. Variable names must begin with a dollar-sign (<code>$</code>).<p>
<div class="example">
<pre class="input"><code>$button_width: 100px;
.button { width: $button_width; }
</code></pre>
<pre class="output"><code>.button { width: 100px; }</code></pre>
</div>
<p>Authors can also use lists of primitive values or other variables as the values.</p>
<div class="example">
<pre class="input"><code>$standard_border: 5px solid #ccc;
$just_like_standard_border: $standard_border;
.uses_standard_border {
border: $standard_border;
}
.uses_just_like_standard_border {
border: $just_like_standard_border;
}
</code></pre>
<pre class="output"><code>.uses_standard_border{
border: 5px solid #ccc;
}
.uses_just_like_standard_border {
border: 5px solid #ccc;
}</code></pre>
</div>
<p>Variables are scoped - if the variable is not found in the current object, the variable will be requested in the parent of the current object. If a variable is not found, or an object does not have a parent (such as the stylesheet itself), an empty string is returned. The most recent (last) declaration of a variable $name will be returned.</p>
<div class="example">
<pre class="input"><code>$background_color: #fff;
#body_id {
$background_color: #000;
.container_1 {
background-color: $background_color;
}
.container_2 {
$background-color: #aaa;
background-color: $background-color;
}
}
.container_3 {
background-color: $background_color;
}
</code></pre>
<pre class="output"><code>#body_id .container_1 {
background-color: #000;
}
#body_id .container_2 {
background-color: #aaa;
}
.container_3 {
background-color: #fff;
}</code></pre>
</div>
<p>Variables are treated as properties of the objects they are defined in. Variables declared as properties of included or imported stylesheets are treated as properties of the host stylesheet. Defining a variable in the "global" scope in a stylesheet will make it global in any stylesheet that imports or includes it as well.</p>
<div class="example">
<pre class="input"><code>/* styles1.sss */
$text_color: #fff;
@include url(styles2.sss);
.example {
color: $color;
}</code></pre>
<pre class="input"><code>/* styles2.sss */
$text_color: #000;</code></pre>
<pre class="output"><code>.example {
color: #000;
}</code></pre>
</div>
<h3>See also:</h3>
<ul>
<li><a href="constants.html">Constants</a></li>
<li><a href="property_lookup.html">prop()</a></li>
</ul>
</div>
</body>
</html>
MongoDB Logo MongoDB