-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.html
540 lines (460 loc) · 29.2 KB
/
index.html
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Less extends CSS with dynamic behavior such as variables, mixins, operations and functions. Less runs on both the server-side (with Node.js and Rhino) or client-side (modern browsers only).
">
<meta name="author" content="The Core Less Team">
<title>
Getting started | Less.js
</title>
<link href="https://fonts.googleapis.com/css?family=Noto+Serif|Oxygen" rel="stylesheet">
<!-- Algolia DocSearch styles -->
<link rel="stylesheet" href="https://fastly.jsdelivr.net/npm/@docsearch/css@3">
<!-- Main styles -->
<link href="public/css/index.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- Favicons -->
<link rel="shortcut icon" href="public/ico/favicon.ico">
</head>
<body class="index">
<div class="docs-header" id="content">
<div class="container" style="text-align:center">
<div>
<img src="public/img/less_logo.png" style="max-width: 264px">
<h3>It's CSS, with just a little more.</h3>
<p>Use with Node.js:</p>
<code>npm install -g less</code><br>
<code>> lessc styles.less styles.css</code>
<br><br>
<p>Or the browser:</p>
<code><link rel="stylesheet/less" type="text/css" href="styles.less" /></code><br>
<code><script src="<a href="https://cdn.jsdelivr.net/npm/less">https://cdn.jsdelivr.net/npm/less</a>" ></script></code><br>
<br><br>
<p>Or try <code><a href="http://lesscss.org/less-preview">the online playground</a></code> ! 🆕</p>
</div>
</div>
</div>
<div class="banner">
<div class="container">
View the <a href="https://github.com/less/less.js/blob/master/CHANGELOG.md">Less.js changelog</a>
</div>
</div>
<div class="container docs-container">
<div class="row">
<div class="col-md-3">
<div class="sidebar hidden-print" role="complementary">
<div id="navigation">
<ul class="nav sidenav"><li><a href="#overview">Overview</a></li>
<li><a href="#variables">Variables</a></li>
<li><a href="#mixins">Mixins</a></li>
<li><a href="#nesting">Nesting</a><ul class="nav"><li><a href="#nesting-nested-at-rules-and-bubbling">Nested At-Rules and Bubbling</a></li></ul></li>
<li><a href="#operations">Operations</a><ul class="nav"><li><a href="#operations-calc-exception">calc() exception</a></li></ul></li>
<li><a href="#escaping">Escaping</a></li>
<li><a href="#functions">Functions</a></li>
<li><a href="#namespaces-and-accessors">Namespaces and Accessors</a></li>
<li><a href="#maps">Maps</a></li>
<li><a href="#scope">Scope</a></li>
<li><a href="#comments">Comments</a></li>
<li><a href="#importing">Importing</a></li></ul></div>
<script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?serve=CE7IK5QL&placement=lesscssorg" id="_carbonads_js"></script>
</div>
</div>
<div class="col-md-9" role="main">
<header class="navbar navbar-inverse navbar-fixed-top docs-nav" role="banner">
<div class="container">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".bs-navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<nav class="collapse navbar-collapse bs-navbar-collapse" role="navigation">
<ul class="nav navbar-nav">
<li class="active">
<span>Overview</span>
</li>
<li>
<a href="usage/">Using Less.js</a>
</li>
<li>
<a href="functions/">Functions</a>
</li>
<li>
<a href="features/">In-Depth Guide</a>
</li>
<li>
<a href="tools/">Tools</a>
</li>
<li>
<a href="about/">About</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<div id="docsearch-wrapper">
<div id="docsearch"></div>
</div>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">GitHub <b class="caret"></b></a>
<ul class="dropdown-menu">
<li> <a href="https://github.com/less/less-docs">Docs Repo</a> </li>
<li> <a href="https://github.com/less/less-docs/issues?&state=open">Docs Issues</a> </li>
<li class="divider"></li>
<li> <a href="https://github.com/less/less.js.git">Less Repo</a> </li>
<li> <a href="https://github.com/less/less.js/issues">Less Issues</a> </li>
</ul>
</li>
</ul>
</nav>
</div>
</header>
<div class="panel docs-content">
<div class="docs-section">
<div class="">
<h1 id="overview" class="docs-heading"><span class="anchor-target" id="overview"></span>
<a href="#overview" name="overview" class="anchor glyphicon glyphicon-link"></a>Overview</h1>
</div>
<blockquote>
<p>Less (which stands for Leaner Style Sheets) is a backwards-compatible language extension for CSS. This is the official documentation for Less, the language and Less.js, the JavaScript tool that converts your Less styles to CSS styles.</p>
</blockquote>
<p>Because Less looks just like CSS, learning it is a breeze. Less only makes a few convenient additions to the CSS language, which is one of the reasons it can be learned so quickly.</p>
<ul>
<li><em>For detailed documentation on Less language features, see <a href="../features/">Features</a></em></li>
<li><em>For a list of Less Built-in functions, see <a href="../functions/">Functions</a></em></li>
<li><em>For detailed usage instructions, see <a href="../usage/">Using Less.js</a></em></li>
<li><em>For third-party tools for Less, see <a href="../tools/">Tools</a></em></li>
</ul>
<p>What does Less add to CSS? Here's a quick overview of features.</p>
<h1 id="variables" class="docs-heading"><span class="anchor-target" id="variables"></span>
<a href="#variables" name="variables" class="anchor glyphicon glyphicon-link"></a>Variables</h1>
<p>These are pretty self-explanatory:</p>
<pre><code class="lang-less"><span class="hljs-variable">@width:</span> <span class="hljs-number">10px</span>;
<span class="hljs-variable">@height:</span> <span class="hljs-variable">@width</span> + <span class="hljs-number">10px</span>;
<span class="hljs-id">#header</span> {
<span class="hljs-attribute">width</span>: <span class="hljs-variable">@width</span>;
<span class="hljs-attribute">height</span>: <span class="hljs-variable">@height</span>;
}
</code></pre>
<p>Outputs:</p>
<pre><code class="lang-css"><span class="hljs-id">#header</span> {
<span class="hljs-attribute">width</span>: <span class="hljs-number">10px</span>;
<span class="hljs-attribute">height</span>: <span class="hljs-number">20px</span>;
}
</code></pre>
<p><strong><a href="../features/#variables-feature">Learn More About Variables</a></strong> </p>
<h1 id="mixins" class="docs-heading"><span class="anchor-target" id="mixins"></span>
<a href="#mixins" name="mixins" class="anchor glyphicon glyphicon-link"></a>Mixins</h1>
<p>Mixins are a way of including ("mixing in") a bunch of properties from one rule-set into another rule-set. So say we have the following class:</p>
<pre><code class="lang-css"><span class="hljs-class">.bordered</span> {
<span class="hljs-attribute">border-top</span>: dotted <span class="hljs-number">1px</span> black;
<span class="hljs-attribute">border-bottom</span>: solid <span class="hljs-number">2px</span> black;
}
</code></pre>
<p>And we want to use these properties inside other rule-sets. Well, we just have to drop in the name of the class where we want the properties, like so:</p>
<pre><code class="lang-less"><span class="hljs-id">#menu</span> <span class="hljs-tag">a</span> {
<span class="hljs-attribute">color</span>: <span class="hljs-hexcolor">#111</span>;
<span class="hljs-class">.bordered</span>();
}
<span class="hljs-class">.post</span> <span class="hljs-tag">a</span> {
<span class="hljs-attribute">color</span>: red;
<span class="hljs-class">.bordered</span>();
}
</code></pre>
<p>The properties of the <code>.bordered</code> class will now appear in both <code>#menu a</code> and <code>.post a</code>. (Note that you can also use <code>#ids</code> as mixins.)</p>
<p><strong><a href="../features/#mixins-feature">Learn More About Mixins</a></strong> </p>
<h1 id="nesting" class="docs-heading"><span class="anchor-target" id="nesting"></span>
<a href="#nesting" name="nesting" class="anchor glyphicon glyphicon-link"></a>Nesting</h1>
<p>Less gives you the ability to use nesting instead of, or in combination with cascading. Let's say we have the following CSS:</p>
<pre><code class="lang-css"><span class="hljs-id">#header</span> {
<span class="hljs-attribute">color</span>: black;
}
<span class="hljs-id">#header</span> <span class="hljs-class">.navigation</span> {
<span class="hljs-attribute">font-size</span>: <span class="hljs-number">12px</span>;
}
<span class="hljs-id">#header</span> <span class="hljs-class">.logo</span> {
<span class="hljs-attribute">width</span>: <span class="hljs-number">300px</span>;
}
</code></pre>
<p>In Less, we can also write it this way:</p>
<pre><code class="lang-less"><span class="hljs-id">#header</span> {
<span class="hljs-attribute">color</span>: black;
<span class="hljs-class">.navigation</span> {
<span class="hljs-attribute">font-size</span>: <span class="hljs-number">12px</span>;
}
<span class="hljs-class">.logo</span> {
<span class="hljs-attribute">width</span>: <span class="hljs-number">300px</span>;
}
}
</code></pre>
<p>The resulting code is more concise, and mimics the structure of your HTML.</p>
<p>You can also bundle pseudo-selectors with your mixins using this method. Here's the classic clearfix hack, rewritten as a mixin (<code>&</code> represents the current selector parent):</p>
<pre><code class="lang-less"><span class="hljs-class">.clearfix</span> {
<span class="hljs-attribute">display</span>: block;
<span class="hljs-attribute">zoom</span>: <span class="hljs-number">1</span>;
<span class="hljs-keyword">&</span><span class="hljs-pseudo">:after</span> {
<span class="hljs-attribute">content</span>: <span class="hljs-string">" "</span>;
<span class="hljs-attribute">display</span>: block;
<span class="hljs-attribute">font-size</span>: <span class="hljs-number">0</span>;
<span class="hljs-attribute">height</span>: <span class="hljs-number">0</span>;
<span class="hljs-attribute">clear</span>: both;
<span class="hljs-attribute">visibility</span>: hidden;
}
}
</code></pre>
<p><strong><a href="../features/#parent-selectors-feature">Learn More About Parent Selectors</a></strong> </p>
<h2 id="nesting-nested-at-rules-and-bubbling" class="docs-heading"><span class="anchor-target" id="nesting-nested-at-rules-and-bubbling"></span>
<a href="#nesting-nested-at-rules-and-bubbling" name="nesting-nested-at-rules-and-bubbling" class="anchor glyphicon glyphicon-link"></a>Nested At-Rules and Bubbling</h2>
<p>At-rules such as <code>@media</code> or <code>@supports</code> can be nested in the same way as selectors. The at-rule is placed on top and relative order against other elements inside the same ruleset remains unchanged. This is called bubbling.</p>
<pre><code class="lang-less"><span class="hljs-class">.component</span> {
<span class="hljs-attribute">width</span>: <span class="hljs-number">300px</span>;
<span class="hljs-at_rule">@media</span> (min-width: <span class="hljs-number">768px</span>) {
<span class="hljs-attribute">width</span>: <span class="hljs-number">600px</span>;
<span class="hljs-at_rule">@media</span> (min-resolution: <span class="hljs-number">192dpi</span>) {
<span class="hljs-attribute">background-image</span>: url(<span class="hljs-string">/img/retina2x.png</span>);
}
}
<span class="hljs-at_rule">@media</span> (min-width: <span class="hljs-number">1280px</span>) {
<span class="hljs-attribute">width</span>: <span class="hljs-number">800px</span>;
}
}
</code></pre>
<p>outputs:</p>
<pre><code class="lang-css"><span class="hljs-class">.component</span> {
<span class="hljs-attribute">width</span>: <span class="hljs-number">300px</span>;
}
<span class="hljs-at_rule">@media</span> (min-width: <span class="hljs-number">768px</span>) {
<span class="hljs-class">.component</span> {
<span class="hljs-attribute">width</span>: <span class="hljs-number">600px</span>;
}
}
<span class="hljs-at_rule">@media</span> (min-width: <span class="hljs-number">768px</span>) and (min-resolution: <span class="hljs-number">192dpi</span>) {
<span class="hljs-class">.component</span> {
<span class="hljs-attribute">background-image</span>: url(<span class="hljs-string">/img/retina2x.png</span>);
}
}
<span class="hljs-at_rule">@media</span> (min-width: <span class="hljs-number">1280px</span>) {
<span class="hljs-class">.component</span> {
<span class="hljs-attribute">width</span>: <span class="hljs-number">800px</span>;
}
}
</code></pre>
<h1 id="operations" class="docs-heading"><span class="anchor-target" id="operations"></span>
<a href="#operations" name="operations" class="anchor glyphicon glyphicon-link"></a>Operations</h1>
<p>Arithmetical operations <code>+</code>, <code>-</code>, <code>*</code>, <code>/</code> can operate on any number, color or variable. If it is possible, mathematical operations take units into account and convert numbers before adding, subtracting or comparing them. The result has leftmost explicitly stated unit type. If the conversion is impossible or not meaningful, units are ignored. Example of impossible conversion: px to cm or rad to %.</p>
<pre><code class="lang-less"><span class="hljs-comment">// numbers are converted into the same units</span>
<span class="hljs-variable">@conversion-1:</span> <span class="hljs-number">5cm</span> + <span class="hljs-number">10mm</span>; <span class="hljs-comment">// result is 6cm</span>
<span class="hljs-variable">@conversion-2:</span> <span class="hljs-number">2</span> - <span class="hljs-number">3cm</span> - <span class="hljs-number">5mm</span>; <span class="hljs-comment">// result is -1.5cm</span>
<span class="hljs-comment">// conversion is impossible</span>
<span class="hljs-variable">@incompatible-units:</span> <span class="hljs-number">2</span> + <span class="hljs-number">5px</span> - <span class="hljs-number">3cm</span>; <span class="hljs-comment">// result is 4px</span>
<span class="hljs-comment">// example with variables</span>
<span class="hljs-variable">@base:</span> <span class="hljs-number">5%</span>;
<span class="hljs-variable">@filler:</span> <span class="hljs-variable">@base</span> * <span class="hljs-number">2</span>; <span class="hljs-comment">// result is 10%</span>
<span class="hljs-variable">@other:</span> <span class="hljs-variable">@base</span> + <span class="hljs-variable">@filler</span>; <span class="hljs-comment">// result is 15%</span>
</code></pre>
<p>Multiplication and division do not convert numbers. It would not be meaningful in most cases - a length multiplied by a length gives an area and css does not support specifying areas. Less will operate on numbers as they are and assign explicitly stated unit type to the result.</p>
<pre><code class="lang-less"><span class="hljs-variable">@base:</span> <span class="hljs-number">2cm</span> * <span class="hljs-number">3mm</span>; <span class="hljs-comment">// result is 6cm</span>
</code></pre>
<p>You can also do arithmetic on colors:</p>
<pre><code class="lang-less"><span class="hljs-variable">@color:</span> (<span class="hljs-hexcolor">#224488</span> / <span class="hljs-number">2</span>); <span class="hljs-comment">// result is #112244</span>
<span class="hljs-attribute">background-color</span>: <span class="hljs-hexcolor">#112244</span> + <span class="hljs-hexcolor">#111</span>; <span class="hljs-comment">// result is #223355</span>
</code></pre>
<p>However, you may find Less's <a href="../functions/#color-operations">Color Functions</a> more useful.</p>
<p>From 4.0, No division is performed outside of parens using <code>/</code> operator.</p>
<pre><code class="lang-less"><span class="hljs-variable">@color:</span> <span class="hljs-hexcolor">#222</span> / <span class="hljs-number">2</span>; <span class="hljs-comment">// results in `#222 / 2`, not #111</span>
<span class="hljs-attribute">background-color</span>: (<span class="hljs-hexcolor">#FFFFFF</span> / <span class="hljs-number">16</span>); <span class="hljs-comment">//results is #101010</span>
</code></pre>
<p>You can change <a href="../usage/#less-options-math">Math</a> setting, if you want to make it always work, but not recommended.</p>
<h2 id="operations-calc-exception" class="docs-heading"><span class="anchor-target" id="operations-calc-exception"></span>
<a href="#operations-calc-exception" name="operations-calc-exception" class="anchor glyphicon glyphicon-link"></a>calc() exception</h2>
<p><em>Released <a href="https://github.com/less/less.js/blob/master/CHANGELOG.md">v3.0.0</a></em></p>
<p>For CSS compatibility, <code>calc()</code> does not evaluate math expressions, but will evaluate variables
and math in nested functions.</p>
<pre><code class="lang-less"><span class="hljs-variable">@var:</span> <span class="hljs-number">50vh</span>/<span class="hljs-number">2</span>;
<span class="hljs-attribute">width</span>: <span class="hljs-function">calc</span>(<span class="hljs-number">50%</span> + (<span class="hljs-variable">@var</span> - <span class="hljs-number">20px</span>)); <span class="hljs-comment">// result is calc(50% + (25vh - 20px))</span>
</code></pre>
<h1 id="escaping" class="docs-heading"><span class="anchor-target" id="escaping"></span>
<a href="#escaping" name="escaping" class="anchor glyphicon glyphicon-link"></a>Escaping</h1>
<p>Escaping allows you to use any arbitrary string as property or variable value. Anything inside <code>~"anything"</code> or <code>~'anything'</code> is used as is with no changes except <a href="../features/#variables-feature-variable-interpolation">interpolation</a>.</p>
<pre><code class="lang-less"><span class="hljs-variable">@min768:</span> <span class="hljs-string">~"(min-width: 768px)"</span>;
<span class="hljs-class">.element</span> {
<span class="hljs-at_rule">@media</span> <span class="hljs-variable">@min768</span> {
<span class="hljs-attribute">font-size</span>: <span class="hljs-number">1.2rem</span>;
}
}
</code></pre>
<p>results in:</p>
<pre><code class="lang-less"><span class="hljs-at_rule">@media</span> (min-width: <span class="hljs-number">768px</span>) {
<span class="hljs-class">.element</span> {
<span class="hljs-attribute">font-size</span>: <span class="hljs-number">1.2rem</span>;
}
}
</code></pre>
<p>Note, as of Less 3.5, you can simply write:</p>
<pre><code class="lang-less"><span class="hljs-variable">@min768:</span> (min-width: <span class="hljs-number">768px</span>);
<span class="hljs-class">.element</span> {
<span class="hljs-at_rule">@media</span> <span class="hljs-variable">@min768</span> {
<span class="hljs-attribute">font-size</span>: <span class="hljs-number">1.2rem</span>;
}
}
</code></pre>
<p>In 3.5+, many cases previously requiring "quote-escaping" are not needed.</p>
<h1 id="functions" class="docs-heading"><span class="anchor-target" id="functions"></span>
<a href="#functions" name="functions" class="anchor glyphicon glyphicon-link"></a>Functions</h1>
<p>Less provides a variety of functions which transform colors, manipulate strings and do maths. They are documented fully in the <a href="../functions/">function reference</a>.</p>
<p>Using them is pretty straightforward. The following example uses percentage to convert 0.5 to 50%, increases the saturation of a base color by 5% and then sets the background color to one that is lightened by 25% and spun by 8 degrees:</p>
<pre><code class="lang-less"><span class="hljs-variable">@base:</span> <span class="hljs-hexcolor">#f04615</span>;
<span class="hljs-variable">@width:</span> <span class="hljs-number">0.5</span>;
<span class="hljs-class">.class</span> {
<span class="hljs-attribute">width</span>: <span class="hljs-function">percentage</span>(<span class="hljs-variable">@width</span>); <span class="hljs-comment">// returns `50%`</span>
<span class="hljs-attribute">color</span>: <span class="hljs-function">saturate</span>(<span class="hljs-variable">@base</span>, <span class="hljs-number">5%</span>);
<span class="hljs-attribute">background-color</span>: <span class="hljs-function">spin</span>(<span class="hljs-function">lighten</span>(<span class="hljs-variable">@base</span>, <span class="hljs-number">25%</span>), <span class="hljs-number">8</span>);
}
</code></pre>
<p><strong><a href="../functions/">See: Function Reference</a></strong> </p>
<h1 id="namespaces-and-accessors" class="docs-heading"><span class="anchor-target" id="namespaces-and-accessors"></span>
<a href="#namespaces-and-accessors" name="namespaces-and-accessors" class="anchor glyphicon glyphicon-link"></a>Namespaces and Accessors</h1>
<p>(Not to be confused with <a href="http://www.w3.org/TR/css3-namespace/">CSS <code>@namespace</code></a> or <a href="http://www.w3.org/TR/css3-selectors/#typenmsp">namespace selectors</a>).</p>
<p>Sometimes, you may want to group your mixins, for organizational purposes, or just to offer some encapsulation. You can do this pretty intuitively in Less. Say you want to bundle some mixins and variables under <code>#bundle</code>, for later reuse or distributing:</p>
<pre><code class="lang-less"><span class="hljs-id">#bundle</span>() {
<span class="hljs-class">.button</span> {
<span class="hljs-attribute">display</span>: block;
<span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid black;
<span class="hljs-attribute">background-color</span>: grey;
<span class="hljs-keyword">&</span><span class="hljs-pseudo">:hover</span> {
<span class="hljs-attribute">background-color</span>: white;
}
}
<span class="hljs-class">.tab</span> { ... }
<span class="hljs-class">.citation</span> { ... }
}
</code></pre>
<p>Now if we want to mixin the <code>.button</code> class in our <code>#header a</code>, we can do:</p>
<pre><code class="lang-less"><span class="hljs-id">#header</span> <span class="hljs-tag">a</span> {
<span class="hljs-attribute">color</span>: orange;
<span class="hljs-id">#bundle</span><span class="hljs-class">.button</span>(); <span class="hljs-comment">// can also be written as #bundle > .button</span>
}
</code></pre>
<p>Note: append <code>()</code> to your namespace (e.g. <code>#bundle()</code>) if you don't want it to appear in your CSS output i.e. <code>#bundle .tab</code>.</p>
<h1 id="maps" class="docs-heading"><span class="anchor-target" id="maps"></span>
<a href="#maps" name="maps" class="anchor glyphicon glyphicon-link"></a>Maps</h1>
<p>As of Less 3.5, you can also use mixins and rulesets as maps of values.</p>
<pre><code class="lang-less"><span class="hljs-id">#colors</span>() {
<span class="hljs-attribute">primary</span>: blue;
<span class="hljs-attribute">secondary</span>: green;
}
<span class="hljs-class">.button</span> {
<span class="hljs-attribute">color</span>: #colors[primary];
<span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid #colors[secondary];
}
</code></pre>
<p>This outputs, as expected:</p>
<pre><code class="lang-css"><span class="hljs-class">.button</span> {
<span class="hljs-attribute">color</span>: blue;
<span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid green;
}
</code></pre>
<p><strong><a href="../features/#maps-feature">See also: Maps</a></strong></p>
<h1 id="scope" class="docs-heading"><span class="anchor-target" id="scope"></span>
<a href="#scope" name="scope" class="anchor glyphicon glyphicon-link"></a>Scope</h1>
<p>Scope in Less is very similar to that of CSS. Variables and mixins are first looked for locally, and if they aren't found, it's inherited from the "parent" scope.</p>
<pre><code class="lang-less"><span class="hljs-variable">@var:</span> red;
<span class="hljs-id">#page</span> {
<span class="hljs-variable">@var:</span> white;
<span class="hljs-id">#header</span> {
<span class="hljs-attribute">color</span>: <span class="hljs-variable">@var</span>; <span class="hljs-comment">// white</span>
}
}
</code></pre>
<p>Like CSS custom properties, mixin and variable definitions do not have to be placed before a line where they are referenced. So the following Less code is identical to the previous example:</p>
<pre><code class="lang-less"><span class="hljs-variable">@var:</span> red;
<span class="hljs-id">#page</span> {
<span class="hljs-id">#header</span> {
<span class="hljs-attribute">color</span>: <span class="hljs-variable">@var</span>; <span class="hljs-comment">// white</span>
}
<span class="hljs-variable">@var:</span> white;
}
</code></pre>
<p><strong><a href="../features/#variables-feature-lazy-loading">See also: Lazy Loading</a></strong></p>
<h1 id="comments" class="docs-heading"><span class="anchor-target" id="comments"></span>
<a href="#comments" name="comments" class="anchor glyphicon glyphicon-link"></a>Comments</h1>
<p>Both block-style and inline comments may be used:</p>
<pre><code class="lang-less"><span class="hljs-comment">/* One heck of a block
* style comment! */</span>
<span class="hljs-variable">@var:</span> red;
<span class="hljs-comment">// Get in line!</span>
<span class="hljs-variable">@var:</span> white;
</code></pre>
<h1 id="importing" class="docs-heading"><span class="anchor-target" id="importing"></span>
<a href="#importing" name="importing" class="anchor glyphicon glyphicon-link"></a>Importing</h1>
<p>Importing works pretty much as expected. You can import a <code>.less</code> file, and all the variables in it will be available. The extension is optionally specified for <code>.less</code> files.</p>
<pre><code class="lang-css"><span class="hljs-at_rule">@import</span> <span class="hljs-string">"library"</span>; <span class="hljs-comment">// library.less</span>
<span class="hljs-at_rule">@import</span> <span class="hljs-string">"typo.css"</span>;
</code></pre>
<p><strong><a href="../features/#imports-feature">Learn More About Imports</a></strong> </p>
</div>
</div>
</div>
</div>
</div>
<footer class="footer" role="contentinfo">
<div class="container">
<div class="bs-social">
<ul class="bs-social-buttons">
<li>
<iframe class="github-btn" src="https://ghbtns.com/github-btn.html?user=less&repo=less.js&type=watch&count=true" width="100" height="20" title="Star on GitHub"></iframe>
</li>
<li>
<iframe class="github-btn" src="https://ghbtns.com/github-btn.html?user=less&repo=less.js&type=fork&count=true" width="102" height="20" title="Fork on GitHub"></iframe>
</li>
</ul>
</div>
<p>Less and these docs are maintained by <a href="about/#team">the core Less team</a>.</p>
<p>Documentation source code released under the <a href="https://github.com/less/less-docs/blob/master/LICENSE-MIT" target="_blank">MIT License</a>, documentation under <a href="http://creativecommons.org/licenses/by/3.0/">CC BY 3.0</a>.</p>
<ul class="footer-links">
<li>Currently v4.1.3</li>
<li class="muted">·</li>
<li><a href="https://github.com/less/less.js/issues">Less Language and Compiler Issues</a></li>
<li class="muted">·</li>
<li><a href="https://github.com/less/less-docs/issues?&state=open">Less Docs Issues</a></li>
<li class="muted">·</li>
<li><a href="https://github.com/less/less.js/blob/master/CHANGELOG.md">Changelog</a></li>
</ul>
</div>
</footer>
<!-- Core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://fastly.jsdelivr.net/npm/@docsearch/js@3"></script>
<script type="text/javascript">
docsearch({
appId: 'LELS6COOLE',
apiKey: 'ad081396555d043318b6a9af4f27a9ec',
indexName: 'lesscss',
container: '#docsearch',
debug: false // Set debug to true if you want to inspect the modal
});
</script>
<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/holder/2.2.0/holder.min.js"></script>
<script src="public/js/application.js"></script>
<!-- Global site tag (gtag.js) - Google Analytics 4 (GA4) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-0LBC5XBD1L"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-0LBC5XBD1L');
</script>
</body>
</html>