-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.html
3268 lines (2797 loc) · 187 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
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!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>
Features In-Depth | 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="features">
<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="#features-overview-feature">Overview</a></li>
<li><a href="#variables-feature">Variables</a><ul class="nav"><li><a href="#variables-feature-overview">Overview</a></li>
<li><a href="#variables-feature-variable-interpolation">Variable Interpolation</a></li>
<li><a href="#variables-feature-variable-variables">Variable Variables</a></li>
<li><a href="#variables-feature-lazy-evaluation">Lazy Evaluation</a></li>
<li><a href="#variables-feature-properties-as-variables-new-">Properties as Variables <strong>(NEW!)</strong></a></li>
<li><a href="#variables-feature-default-variables">Default Variables</a></li></ul></li>
<li><a href="#parent-selectors-feature">Parent Selectors</a><ul class="nav"><li><a href="#parent-selectors-feature-multiple-">Multiple <code>&</code></a></li>
<li><a href="#parent-selectors-feature-changing-selector-order">Changing Selector Order</a></li>
<li><a href="#parent-selectors-feature-combinatorial-explosion">Combinatorial Explosion</a></li></ul></li>
<li><a href="#import-atrules-feature">@import At-Rules</a><ul class="nav"><li><a href="#import-atrules-feature-file-extensions">File Extensions</a></li>
<li><a href="#import-atrules-feature-import-options">Import Options</a></li>
<li><a href="#import-atrules-feature-reference">reference</a></li>
<li><a href="#import-atrules-feature-inline">inline</a></li>
<li><a href="#import-atrules-feature-less">less</a></li>
<li><a href="#import-atrules-feature-css">css</a></li>
<li><a href="#import-atrules-feature-once">once</a></li>
<li><a href="#import-atrules-feature-multiple">multiple</a></li>
<li><a href="#import-atrules-feature-optional">optional</a></li></ul></li>
<li><a href="#extend-feature">Extend</a><ul class="nav"><li><a href="#extend-feature-extend-syntax">Extend Syntax</a></li>
<li><a href="#extend-feature-extend-attached-to-selector">Extend Attached to Selector</a></li>
<li><a href="#extend-feature-extend-inside-ruleset">Extend Inside Ruleset</a></li>
<li><a href="#extend-feature-extending-nested-selectors">Extending Nested Selectors</a></li>
<li><a href="#extend-feature-exact-matching-with-extend">Exact Matching with Extend</a></li>
<li><a href="#extend-feature-nth-expression">nth Expression</a></li>
<li><a href="#extend-feature-extend-all">Extend "all"</a></li>
<li><a href="#extend-feature-selector-interpolation-with-extend">Selector Interpolation with Extend</a></li>
<li><a href="#extend-feature-scoping-extend-inside-media">Scoping / Extend Inside @media</a></li>
<li><a href="#extend-feature-duplication-detection">Duplication Detection</a></li>
<li><a href="#extend-feature-use-cases-for-extend">Use Cases for Extend</a></li></ul></li>
<li><a href="#merge-feature">Merge properties</a><ul class="nav"><li><a href="#merge-feature-comma">Comma</a></li>
<li><a href="#merge-feature-space">Space</a></li></ul></li>
<li><a href="#mixins-feature">Mixins</a><ul class="nav"><li><a href="#mixins-feature-mixins-with-parentheses">Mixins With Parentheses</a></li>
<li><a href="#mixins-feature-selectors-in-mixins">Selectors in Mixins</a></li>
<li><a href="#mixins-feature-namespaces">Namespaces</a></li>
<li><a href="#mixins-feature-guarded-namespaces">Guarded Namespaces</a></li>
<li><a href="#mixins-feature-the-important-keyword">The <code>!important</code> keyword</a></li>
<li><a href="#mixins-feature-mixins-parametric-feature">Parametric Mixins</a></li>
<li><a href="#mixins-feature-pattern-matching">Pattern-matching</a></li>
<li><a href="#mixins-feature-mixins-as-functions-feature">Using Mixins as Functions</a></li>
<li><a href="#mixins-feature-loops-feature">Recursive Mixins</a></li>
<li><a href="#mixins-feature-mixin-guards-feature">Mixin Guards</a></li>
<li><a href="#mixins-feature-mixin-aliasing-feature">Aliasing Mixins</a></li></ul></li>
<li><a href="#detached-rulesets-feature">Detached Rulesets</a><ul class="nav"><li><a href="#detached-rulesets-feature-scoping">Scoping</a></li>
<li><a href="#detached-rulesets-feature-property-variable-accessors">Property / variable accessors</a></li></ul></li>
<li><a href="#maps-feature">Maps</a><ul class="nav"><li><a href="#maps-feature-using-variable-variables-in-lookups">Using variable variables in lookups</a></li></ul></li>
<li><a href="#scope-feature">Scope</a><ul class="nav"><li><a href="#scope-feature-mixin-scope-features">Mixin scope features</a></li>
<li><a href="#scope-feature-deprecated-mixin-scope-features">Deprecated mixin scope features</a></li>
<li><a href="#scope-feature-tips-tricks">Tips & Tricks</a></li></ul></li>
<li><a href="#css-guards-feature">CSS Guards</a></li>
<li><a href="#plugin-atrules-feature">@plugin At-Rules</a><ul class="nav"><li><a href="#plugin-atrules-feature-writing-your-first-plugin">Writing your first plugin</a></li>
<li><a href="#plugin-atrules-feature-plugin-scope">Plugin Scope</a></li>
<li><a href="#plugin-atrules-feature-null-functions">Null Functions</a></li>
<li><a href="#plugin-atrules-feature-the-less-js-plugin-object">The Less.js Plugin Object</a></li>
<li><a href="#plugin-atrules-feature-pre-loaded-plugins">Pre-Loaded Plugins</a></li></ul></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>
<a href="../#">Overview</a>
</li>
<li>
<a href="../usage/">Using Less.js</a>
</li>
<li>
<a href="../functions/">Functions</a>
</li>
<li class="active">
<span>In-Depth Guide</span>
</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">
<!-- Overview -->
<div class="docs-section">
<h1 id="features-overview-feature" class="docs-heading"><span class="anchor-target" id="features-overview-feature"></span>
<a href="#features-overview-feature" name="features-overview-feature" class="anchor glyphicon glyphicon-link"></a>Overview</h1>
<div class="section-content">
<a class="glyphicon glyphicon-pencil source-link right" href="https://github.com/less/less-docs/blob/master/content/features/overview.md" data-content="overviewmd" target="_blank"></a>
<a id="overviewmd" href="https://github.com/less/less-docs/blob/master/content/features/overview.md" target="_blank">Edit the markdown source for "overview"
<span class="glyphicon glyphicon-new-window"></span>
</a>
<!-- overview -->
<blockquote>
<p>An in-depth guide to features of the LESS language. See the <a href="/#overview">Overview</a> for a quick summary of Less.</p>
</blockquote>
<p><em>For an in-depth guide to installing and setting up a Less environment, as well as documentation on developing for Less, see: <a href="/usage">Using Less.js</a>.</em></p>
<br>
</div>
</div>
<!-- Variables -->
<div class="docs-section">
<h1 id="variables-feature" class="docs-heading"><span class="anchor-target" id="variables-feature"></span>
<a href="#variables-feature" name="variables-feature" class="anchor glyphicon glyphicon-link"></a>Variables</h1>
<div class="section-content">
<a class="glyphicon glyphicon-pencil source-link right" href="https://github.com/less/less-docs/blob/master/content/features/variables.md" data-content="variablesmd" target="_blank"></a>
<a id="variablesmd" href="https://github.com/less/less-docs/blob/master/content/features/variables.md" target="_blank">Edit the markdown source for "variables"
<span class="glyphicon glyphicon-new-window"></span>
</a>
<!-- variables -->
<blockquote>
<p>Control commonly used values in a single location.</p>
</blockquote>
<h3 id="variables-feature-overview" class="docs-heading"><span class="anchor-target" id="variables-feature-overview"></span>
<a href="#variables-feature-overview" name="variables-feature-overview" class="anchor glyphicon glyphicon-link"></a>Overview</h3>
<p>It's not uncommon to see the same value repeated dozens <em>if not hundreds of times</em> across your stylesheets:</p>
<pre><code class="lang-css"><span class="hljs-tag">a</span>,
<span class="hljs-class">.link</span> {
<span class="hljs-attribute">color</span>: <span class="hljs-hexcolor">#428bca</span>;
}
<span class="hljs-class">.widget</span> {
<span class="hljs-attribute">color</span>: <span class="hljs-hexcolor">#fff</span>;
<span class="hljs-attribute">background</span>: <span class="hljs-hexcolor">#428bca</span>;
}
</code></pre>
<p>Variables make your code easier to maintain by giving you a way to control those values from a single location:</p>
<pre><code class="lang-less"><span class="hljs-comment">// Variables</span>
<span class="hljs-variable">@link-color:</span> <span class="hljs-hexcolor">#428bca</span>; <span class="hljs-comment">// sea blue</span>
<span class="hljs-variable">@link-color-hover:</span> <span class="hljs-function">darken</span>(<span class="hljs-variable">@link-color</span>, <span class="hljs-number">10%</span>);
<span class="hljs-comment">// Usage</span>
<span class="hljs-tag">a</span>,
<span class="hljs-class">.link</span> {
<span class="hljs-attribute">color</span>: <span class="hljs-variable">@link-color</span>;
}
<span class="hljs-tag">a</span><span class="hljs-pseudo">:hover</span> {
<span class="hljs-attribute">color</span>: <span class="hljs-variable">@link-color-hover</span>;
}
<span class="hljs-class">.widget</span> {
<span class="hljs-attribute">color</span>: <span class="hljs-hexcolor">#fff</span>;
<span class="hljs-attribute">background</span>: <span class="hljs-variable">@link-color</span>;
}
</code></pre>
<h3 id="variables-feature-variable-interpolation" class="docs-heading"><span class="anchor-target" id="variables-feature-variable-interpolation"></span>
<a href="#variables-feature-variable-interpolation" name="variables-feature-variable-interpolation" class="anchor glyphicon glyphicon-link"></a>Variable Interpolation</h3>
<p>The examples above focused on using variables to control <em>values in CSS rules</em>, but they can also be used in other places as well, such as selector names, property names, URLs and <code>@import</code> statements.</p>
<h4 id="variables-feature-selectors" class="docs-heading"><span class="anchor-target" id="variables-feature-selectors"></span>
<a href="#variables-feature-selectors" name="variables-feature-selectors" class="anchor glyphicon glyphicon-link"></a>Selectors</h4>
<p><em>v1.4.0</em></p>
<pre><code class="lang-less"><span class="hljs-comment">// Variables</span>
<span class="hljs-variable">@my-selector:</span> banner;
<span class="hljs-comment">// Usage</span>
<span class="hljs-class">.@{my-selector}</span> {
<span class="hljs-attribute">font-weight</span>: bold;
<span class="hljs-attribute">line-height</span>: <span class="hljs-number">40px</span>;
<span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span> auto;
}
</code></pre>
<p>Compiles to:</p>
<pre><code class="lang-css"><span class="hljs-class">.banner</span> {
<span class="hljs-attribute">font-weight</span>: bold;
<span class="hljs-attribute">line-height</span>: <span class="hljs-number">40px</span>;
<span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span> auto;
}
</code></pre>
<h4 id="variables-feature-urls" class="docs-heading"><span class="anchor-target" id="variables-feature-urls"></span>
<a href="#variables-feature-urls" name="variables-feature-urls" class="anchor glyphicon glyphicon-link"></a>URLs</h4>
<pre><code class="lang-less"><span class="hljs-comment">// Variables</span>
<span class="hljs-variable">@images:</span> <span class="hljs-string">"../img"</span>;
<span class="hljs-comment">// Usage</span>
<span class="hljs-tag">body</span> {
<span class="hljs-attribute">color</span>: <span class="hljs-hexcolor">#444</span>;
<span class="hljs-attribute">background</span>: url(<span class="hljs-string">"@{images}/white-sand.png"</span>);
}
</code></pre>
<h4 id="variables-feature-import-statements" class="docs-heading"><span class="anchor-target" id="variables-feature-import-statements"></span>
<a href="#variables-feature-import-statements" name="variables-feature-import-statements" class="anchor glyphicon glyphicon-link"></a>Import Statements</h4>
<p><em>v1.4.0</em></p>
<p>Syntax: <code>@import "@{themes}/tidal-wave.less";</code></p>
<p>Note that before v2.0.0, only variables which have been declared in the root or current scope were considered and that only the current file and calling files were considered when looking for a variable.</p>
<p>Example:</p>
<pre><code class="lang-less"><span class="hljs-comment">// Variables</span>
<span class="hljs-variable">@themes:</span> <span class="hljs-string">"../../src/themes"</span>;
<span class="hljs-comment">// Usage</span>
<span class="hljs-at_rule">@import</span> <span class="hljs-string">"@{themes}/tidal-wave.less"</span>;
</code></pre>
<h4 id="variables-feature-properties" class="docs-heading"><span class="anchor-target" id="variables-feature-properties"></span>
<a href="#variables-feature-properties" name="variables-feature-properties" class="anchor glyphicon glyphicon-link"></a>Properties</h4>
<p><em>v1.6.0</em></p>
<pre><code class="lang-less"><span class="hljs-variable">@property:</span> color;
<span class="hljs-class">.widget</span> {
<span class="hljs-attribute">@{property}</span>: <span class="hljs-hexcolor">#0ee</span>;
<span class="hljs-attribute">background-@{property}</span>: <span class="hljs-hexcolor">#999</span>;
}
</code></pre>
<p>Compiles to:</p>
<pre><code class="lang-css"><span class="hljs-class">.widget</span> {
<span class="hljs-attribute">color</span>: <span class="hljs-hexcolor">#0ee</span>;
<span class="hljs-attribute">background-color</span>: <span class="hljs-hexcolor">#999</span>;
}
</code></pre>
<h3 id="variables-feature-variable-variables" class="docs-heading"><span class="anchor-target" id="variables-feature-variable-variables"></span>
<a href="#variables-feature-variable-variables" name="variables-feature-variable-variables" class="anchor glyphicon glyphicon-link"></a>Variable Variables</h3>
<p>In Less, you can define a variable's name using another variable.</p>
<pre><code class="lang-less"><span class="hljs-variable">@primary:</span> green;
<span class="hljs-variable">@secondary:</span> blue;
<span class="hljs-class">.section</span> {
<span class="hljs-variable">@color:</span> primary;
<span class="hljs-class">.element</span> {
<span class="hljs-attribute">color</span>: <span class="hljs-variable">@@color</span>;
}
}
</code></pre>
<p>Which compiles to:</p>
<pre><code class="lang-less"><span class="hljs-class">.section</span> <span class="hljs-class">.element</span> {
<span class="hljs-attribute">color</span>: green;
}
</code></pre>
<p><span class="anchor-target" id="variables-feature-lazy-loading"></span>
<!-- ^ please keep old anchor to not break zillion outer links --></p>
<h3 id="variables-feature-lazy-evaluation" class="docs-heading"><span class="anchor-target" id="variables-feature-lazy-evaluation"></span>
<a href="#variables-feature-lazy-evaluation" name="variables-feature-lazy-evaluation" class="anchor glyphicon glyphicon-link"></a>Lazy Evaluation</h3>
<blockquote>
<p>Variables do not have to be declared before being used.</p>
</blockquote>
<p>Valid Less snippet:</p>
<pre><code class="lang-less"><span class="hljs-class">.lazy-eval</span> {
<span class="hljs-attribute">width</span>: <span class="hljs-variable">@var</span>;
}
<span class="hljs-variable">@var:</span> <span class="hljs-variable">@a</span>;
<span class="hljs-variable">@a:</span> <span class="hljs-number">9%</span>;
</code></pre>
<p>this is valid Less too:</p>
<pre><code class="lang-less"><span class="hljs-class">.lazy-eval</span> {
<span class="hljs-attribute">width</span>: <span class="hljs-variable">@var</span>;
<span class="hljs-variable">@a:</span> <span class="hljs-number">9%</span>;
}
<span class="hljs-variable">@var:</span> <span class="hljs-variable">@a</span>;
<span class="hljs-variable">@a:</span> <span class="hljs-number">100%</span>;
</code></pre>
<p>both compile into:</p>
<pre><code class="lang-css"><span class="hljs-class">.lazy-eval</span> {
<span class="hljs-attribute">width</span>: <span class="hljs-number">9%</span>;
}
</code></pre>
<p>When defining a variable twice, the last definition of the variable is used, searching from the current scope upwards. This is similar to css itself where the last property inside a definition is used to determine the value.</p>
<p>For instance:</p>
<pre><code class="lang-less"><span class="hljs-variable">@var:</span> <span class="hljs-number">0</span>;
<span class="hljs-class">.class</span> {
<span class="hljs-variable">@var:</span> <span class="hljs-number">1</span>;
<span class="hljs-class">.brass</span> {
<span class="hljs-variable">@var:</span> <span class="hljs-number">2</span>;
<span class="hljs-attribute">three</span>: <span class="hljs-variable">@var</span>;
<span class="hljs-variable">@var:</span> <span class="hljs-number">3</span>;
}
<span class="hljs-attribute">one</span>: <span class="hljs-variable">@var</span>;
}
</code></pre>
<p>Compiles to:</p>
<pre><code class="lang-css"><span class="hljs-class">.class</span> {
<span class="hljs-attribute">one</span>: <span class="hljs-number">1</span>;
}
<span class="hljs-class">.class</span> <span class="hljs-class">.brass</span> {
<span class="hljs-attribute">three</span>: <span class="hljs-number">3</span>;
}
</code></pre>
<p>Essentially, each scope has a "final" value, similar to properties in the browser, like this example using custom properties:</p>
<pre><code class="lang-css"><span class="hljs-class">.header</span> {
<span class="hljs-attribute">--color</span>: white;
<span class="hljs-attribute">color</span>: <span class="hljs-function">var</span>(--color); <span class="hljs-comment">// the color is black</span>
<span class="hljs-attribute">--color</span>: black;
}
</code></pre>
<p>This means that, unlike other CSS pre-processing languages, Less variables behave very much like CSS's.</p>
<h3 id="variables-feature-properties-as-variables-new-" class="docs-heading"><span class="anchor-target" id="variables-feature-properties-as-variables-new-"></span>
<a href="#variables-feature-properties-as-variables-new-" name="variables-feature-properties-as-variables-new-" class="anchor glyphicon glyphicon-link"></a>Properties as Variables <strong>(NEW!)</strong></h3>
<p><em>v3.0.0</em></p>
<p>You can easily treat properties like variables using the <code>$prop</code> syntax. Sometimes this can
make your code a little lighter.</p>
<pre><code class="lang-less"><span class="hljs-class">.widget</span> {
<span class="hljs-attribute">color</span>: <span class="hljs-hexcolor">#efefef</span>;
<span class="hljs-attribute">background-color</span>: $color;
}
</code></pre>
<p>Compiles to:</p>
<pre><code class="lang-css"><span class="hljs-class">.widget</span> {
<span class="hljs-attribute">color</span>: <span class="hljs-hexcolor">#efefef</span>;
<span class="hljs-attribute">background-color</span>: <span class="hljs-hexcolor">#efefef</span>;
}
</code></pre>
<p>Note that, like variables, Less will choose the last property within the current/parent scope
as being the "final" value.</p>
<pre><code class="lang-less"><span class="hljs-class">.block</span> {
<span class="hljs-attribute">color</span>: red;
<span class="hljs-class">.inner</span> {
<span class="hljs-attribute">background-color</span>: $color;
}
<span class="hljs-attribute">color</span>: blue;
}
</code></pre>
<p>Compiles to:</p>
<pre><code class="lang-css"><span class="hljs-class">.block</span> {
<span class="hljs-attribute">color</span>: red;
<span class="hljs-attribute">color</span>: blue;
}
<span class="hljs-class">.block</span> <span class="hljs-class">.inner</span> {
<span class="hljs-attribute">background-color</span>: blue;
}
</code></pre>
<h3 id="variables-feature-default-variables" class="docs-heading"><span class="anchor-target" id="variables-feature-default-variables"></span>
<a href="#variables-feature-default-variables" name="variables-feature-default-variables" class="anchor glyphicon glyphicon-link"></a>Default Variables</h3>
<p>We sometimes get requests for default variables - an ability to set a variable only if it is not already set. This feature is not required because you can easily override a variable by putting the definition afterwards.</p>
<p>For instance:</p>
<pre><code class="lang-less"><span class="hljs-comment">// library</span>
<span class="hljs-variable">@base-color:</span> green;
<span class="hljs-variable">@dark-color:</span> <span class="hljs-function">darken</span>(<span class="hljs-variable">@base-color</span>, <span class="hljs-number">10%</span>);
<span class="hljs-comment">// use of library</span>
<span class="hljs-at_rule">@import</span> <span class="hljs-string">"library.less"</span>;
<span class="hljs-variable">@base-color:</span> red;
</code></pre>
<p>This works fine because of <a href="#variables-feature-lazy-loading">Lazy Loading</a> - <code>@base-color</code> is overridden and <code>@dark-color</code> is a dark red.</p>
<br>
</div>
</div>
<!-- Parent Selectors -->
<div class="docs-section">
<h1 id="parent-selectors-feature" class="docs-heading"><span class="anchor-target" id="parent-selectors-feature"></span>
<a href="#parent-selectors-feature" name="parent-selectors-feature" class="anchor glyphicon glyphicon-link"></a>Parent Selectors</h1>
<div class="section-content">
<a class="glyphicon glyphicon-pencil source-link right" href="https://github.com/less/less-docs/blob/master/content/features/parent-selectors.md" data-content="parent-selectorsmd" target="_blank"></a>
<a id="parent-selectorsmd" href="https://github.com/less/less-docs/blob/master/content/features/parent-selectors.md" target="_blank">Edit the markdown source for "parent-selectors"
<span class="glyphicon glyphicon-new-window"></span>
</a>
<!-- parent-selectors -->
<blockquote>
<p>Referencing parent selectors with <code>&</code></p>
</blockquote>
<p>The <code>&</code> operator represents the parent selectors of a <a href="#features-overview-feature-nested-rules">nested rule</a> and is most commonly used when applying a modifying class or pseudo-class to an existing selector:</p>
<pre><code class="lang-less"><span class="hljs-tag">a</span> {
<span class="hljs-attribute">color</span>: blue;
<span class="hljs-keyword">&</span><span class="hljs-pseudo">:hover</span> {
<span class="hljs-attribute">color</span>: green;
}
}
</code></pre>
<p>results in:</p>
<pre><code class="lang-css"><span class="hljs-tag">a</span> {
<span class="hljs-attribute">color</span>: blue;
}
<span class="hljs-tag">a</span><span class="hljs-pseudo">:hover</span> {
<span class="hljs-attribute">color</span>: green;
}
</code></pre>
<p>Notice that without the <code>&</code>, the above example would result in <code>a :hover</code> rule (a descendant selector that matches hovered elements inside of <code><a></code> tags) and this is not what we typically would want with the nested <code>:hover</code>.</p>
<p>The "parent selectors" operator has a variety of uses. Basically any time you need the selectors of the nested rules to be combined in other ways than the default. For example another typical use of the <code>&</code> is to produce repetitive class names:</p>
<pre><code class="lang-less"><span class="hljs-class">.button</span> {
<span class="hljs-keyword">&</span><span class="hljs-tag">-ok</span> {
<span class="hljs-attribute">background-image</span>: url(<span class="hljs-string">"ok.png"</span>);
}
<span class="hljs-keyword">&</span><span class="hljs-tag">-cancel</span> {
<span class="hljs-attribute">background-image</span>: url(<span class="hljs-string">"cancel.png"</span>);
}
<span class="hljs-keyword">&</span><span class="hljs-tag">-custom</span> {
<span class="hljs-attribute">background-image</span>: url(<span class="hljs-string">"custom.png"</span>);
}
}
</code></pre>
<p>output:</p>
<pre><code class="lang-css"><span class="hljs-class">.button-ok</span> {
<span class="hljs-attribute">background-image</span>: url(<span class="hljs-string">"ok.png"</span>);
}
<span class="hljs-class">.button-cancel</span> {
<span class="hljs-attribute">background-image</span>: url(<span class="hljs-string">"cancel.png"</span>);
}
<span class="hljs-class">.button-custom</span> {
<span class="hljs-attribute">background-image</span>: url(<span class="hljs-string">"custom.png"</span>);
}
</code></pre>
<h3 id="parent-selectors-feature-multiple-" class="docs-heading"><span class="anchor-target" id="parent-selectors-feature-multiple-"></span>
<a href="#parent-selectors-feature-multiple-" name="parent-selectors-feature-multiple-" class="anchor glyphicon glyphicon-link"></a>Multiple <code>&</code></h3>
<p><code>&</code> may appear more than once within a selector. This makes it possible to repeatedly refer to a parent selector without repeating its name.</p>
<pre><code class="lang-less"><span class="hljs-class">.link</span> {
<span class="hljs-keyword">&</span> + <span class="hljs-keyword">&</span> {
<span class="hljs-attribute">color</span>: red;
}
<span class="hljs-keyword">&</span> <span class="hljs-keyword">&</span> {
<span class="hljs-attribute">color</span>: green;
}
<span class="hljs-keyword">&</span><span class="hljs-keyword">&</span> {
<span class="hljs-attribute">color</span>: blue;
}
<span class="hljs-keyword">&</span>, <span class="hljs-keyword">&</span><span class="hljs-tag">ish</span> {
<span class="hljs-attribute">color</span>: cyan;
}
}
</code></pre>
<p>will output:</p>
<pre><code class="lang-css"><span class="hljs-class">.link</span> + <span class="hljs-class">.link</span> {
<span class="hljs-attribute">color</span>: red;
}
<span class="hljs-class">.link</span> <span class="hljs-class">.link</span> {
<span class="hljs-attribute">color</span>: green;
}
<span class="hljs-class">.link</span><span class="hljs-class">.link</span> {
<span class="hljs-attribute">color</span>: blue;
}
<span class="hljs-class">.link</span>, <span class="hljs-class">.linkish</span> {
<span class="hljs-attribute">color</span>: cyan;
}
</code></pre>
<p>Note that <code>&</code> represents all parent selectors (not just the nearest ancestor) so the following example:</p>
<pre><code class="lang-less"><span class="hljs-class">.grand</span> {
<span class="hljs-class">.parent</span> {
<span class="hljs-keyword">&</span> > <span class="hljs-keyword">&</span> {
<span class="hljs-attribute">color</span>: red;
}
<span class="hljs-keyword">&</span> <span class="hljs-keyword">&</span> {
<span class="hljs-attribute">color</span>: green;
}
<span class="hljs-keyword">&</span><span class="hljs-keyword">&</span> {
<span class="hljs-attribute">color</span>: blue;
}
<span class="hljs-keyword">&</span>, <span class="hljs-keyword">&</span><span class="hljs-tag">ish</span> {
<span class="hljs-attribute">color</span>: cyan;
}
}
}
</code></pre>
<p>results in:</p>
<pre><code class="lang-css"><span class="hljs-class">.grand</span> <span class="hljs-class">.parent</span> > <span class="hljs-class">.grand</span> <span class="hljs-class">.parent</span> {
<span class="hljs-attribute">color</span>: red;
}
<span class="hljs-class">.grand</span> <span class="hljs-class">.parent</span> <span class="hljs-class">.grand</span> <span class="hljs-class">.parent</span> {
<span class="hljs-attribute">color</span>: green;
}
<span class="hljs-class">.grand</span> <span class="hljs-class">.parent</span><span class="hljs-class">.grand</span> <span class="hljs-class">.parent</span> {
<span class="hljs-attribute">color</span>: blue;
}
<span class="hljs-class">.grand</span> <span class="hljs-class">.parent</span>,
<span class="hljs-class">.grand</span> <span class="hljs-class">.parentish</span> {
<span class="hljs-attribute">color</span>: cyan;
}
</code></pre>
<h3 id="parent-selectors-feature-changing-selector-order" class="docs-heading"><span class="anchor-target" id="parent-selectors-feature-changing-selector-order"></span>
<a href="#parent-selectors-feature-changing-selector-order" name="parent-selectors-feature-changing-selector-order" class="anchor glyphicon glyphicon-link"></a>Changing Selector Order</h3>
<p>It can be useful to prepend a selector to the inherited (parent) selectors. This can be done by putting the <code>&</code> after current selector.
For example, when using Modernizr, you might want to specify different rules based on supported features:</p>
<pre><code class="lang-less"><span class="hljs-class">.header</span> {
<span class="hljs-class">.menu</span> {
<span class="hljs-attribute">border-radius</span>: <span class="hljs-number">5px</span>;
<span class="hljs-class">.no-borderradius</span> <span class="hljs-keyword">&</span> {
<span class="hljs-attribute">background-image</span>: url(<span class="hljs-string">'images/button-background.png'</span>);
}
}
}
</code></pre>
<p>The selector <code>.no-borderradius &</code> will prepend <code>.no-borderradius</code> to its parent <code>.header .menu</code> to form the<code>.no-borderradius .header .menu</code> on output:</p>
<pre><code class="lang-css"><span class="hljs-class">.header</span> <span class="hljs-class">.menu</span> {
<span class="hljs-attribute">border-radius</span>: <span class="hljs-number">5px</span>;
}
<span class="hljs-class">.no-borderradius</span> <span class="hljs-class">.header</span> <span class="hljs-class">.menu</span> {
<span class="hljs-attribute">background-image</span>: url(<span class="hljs-string">'images/button-background.png'</span>);
}
</code></pre>
<h3 id="parent-selectors-feature-combinatorial-explosion" class="docs-heading"><span class="anchor-target" id="parent-selectors-feature-combinatorial-explosion"></span>
<a href="#parent-selectors-feature-combinatorial-explosion" name="parent-selectors-feature-combinatorial-explosion" class="anchor glyphicon glyphicon-link"></a>Combinatorial Explosion</h3>
<p><code>&</code> can also be used to generate every possible permutation of selectors in a comma separated list:</p>
<pre><code class="lang-less"><span class="hljs-tag">p</span>, <span class="hljs-tag">a</span>, <span class="hljs-tag">ul</span>, <span class="hljs-tag">li</span> {
<span class="hljs-attribute">border-top</span>: <span class="hljs-number">2px</span> dotted <span class="hljs-hexcolor">#366</span>;
<span class="hljs-keyword">&</span> + <span class="hljs-keyword">&</span> {
<span class="hljs-attribute">border-top</span>: <span class="hljs-number">0</span>;
}
}
</code></pre>
<p>This expands to all possible (16) combinations of the specified elements:</p>
<pre><code class="lang-css"><span class="hljs-tag">p</span>,
<span class="hljs-tag">a</span>,
<span class="hljs-tag">ul</span>,
<span class="hljs-tag">li</span> {
<span class="hljs-attribute">border-top</span>: <span class="hljs-number">2px</span> dotted <span class="hljs-hexcolor">#366</span>;
}
<span class="hljs-tag">p</span> + <span class="hljs-tag">p</span>,
<span class="hljs-tag">p</span> + <span class="hljs-tag">a</span>,
<span class="hljs-tag">p</span> + <span class="hljs-tag">ul</span>,
<span class="hljs-tag">p</span> + <span class="hljs-tag">li</span>,
<span class="hljs-tag">a</span> + <span class="hljs-tag">p</span>,
<span class="hljs-tag">a</span> + <span class="hljs-tag">a</span>,
<span class="hljs-tag">a</span> + <span class="hljs-tag">ul</span>,
<span class="hljs-tag">a</span> + <span class="hljs-tag">li</span>,
<span class="hljs-tag">ul</span> + <span class="hljs-tag">p</span>,
<span class="hljs-tag">ul</span> + <span class="hljs-tag">a</span>,
<span class="hljs-tag">ul</span> + <span class="hljs-tag">ul</span>,
<span class="hljs-tag">ul</span> + <span class="hljs-tag">li</span>,
<span class="hljs-tag">li</span> + <span class="hljs-tag">p</span>,
<span class="hljs-tag">li</span> + <span class="hljs-tag">a</span>,
<span class="hljs-tag">li</span> + <span class="hljs-tag">ul</span>,
<span class="hljs-tag">li</span> + <span class="hljs-tag">li</span> {
<span class="hljs-attribute">border-top</span>: <span class="hljs-number">0</span>;
}
</code></pre>
<br>
</div>
</div>
<!-- @import At-Rules -->
<div class="docs-section">
<h1 id="import-atrules-feature" class="docs-heading"><span class="anchor-target" id="import-atrules-feature"></span>
<a href="#import-atrules-feature" name="import-atrules-feature" class="anchor glyphicon glyphicon-link"></a>@import At-Rules</h1>
<div class="section-content">
<a class="glyphicon glyphicon-pencil source-link right" href="https://github.com/less/less-docs/blob/master/content/features/imports.md" data-content="importsmd" target="_blank"></a>
<a id="importsmd" href="https://github.com/less/less-docs/blob/master/content/features/imports.md" target="_blank">Edit the markdown source for "imports"
<span class="glyphicon glyphicon-new-window"></span>
</a>
<!-- imports -->
<blockquote>
<p>Import styles from other style sheets</p>
</blockquote>
<p>In standard CSS, <code>@import</code> at-rules must precede all other types of rules. But Less doesn't care where you put <code>@import</code> statements.</p>
<p>Example:</p>
<pre><code class="lang-less"><span class="hljs-class">.foo</span> {
<span class="hljs-attribute">background</span>: <span class="hljs-hexcolor">#900</span>;
}
<span class="hljs-at_rule">@import</span> <span class="hljs-string">"this-is-valid.less"</span>;
</code></pre>
<h2 id="import-atrules-feature-file-extensions" class="docs-heading"><span class="anchor-target" id="import-atrules-feature-file-extensions"></span>
<a href="#import-atrules-feature-file-extensions" name="import-atrules-feature-file-extensions" class="anchor glyphicon glyphicon-link"></a>File Extensions</h2>
<p><code>@import</code> statements may be treated differently by Less depending on the file extension:</p>
<ul>
<li>If the file has a <code>.css</code> extension it will be treated as CSS and the <code>@import</code> statement left as-is (see the <a href="#import-atrules-feature-inline">inline option</a> below).</li>
<li>If it has <em>any other extension</em> it will be treated as Less and imported.</li>
<li>If it does not have an extension, <code>.less</code> will be appended and it will be included as a imported Less file.</li>
</ul>
<p>Examples:</p>
<pre><code class="lang-less"><span class="hljs-at_rule">@import</span> <span class="hljs-string">"foo"</span>; <span class="hljs-comment">// foo.less is imported</span>
<span class="hljs-at_rule">@import</span> <span class="hljs-string">"foo.less"</span>; <span class="hljs-comment">// foo.less is imported</span>
<span class="hljs-at_rule">@import</span> <span class="hljs-string">"foo.php"</span>; <span class="hljs-comment">// foo.php imported as a Less file</span>
<span class="hljs-at_rule">@import</span> <span class="hljs-string">"foo.css"</span>; <span class="hljs-comment">// statement left in place, as-is</span>
</code></pre>
<p>The following options can be used to override this behavior.</p>
<h2 id="import-atrules-feature-import-options" class="docs-heading"><span class="anchor-target" id="import-atrules-feature-import-options"></span>
<a href="#import-atrules-feature-import-options" name="import-atrules-feature-import-options" class="anchor glyphicon glyphicon-link"></a>Import Options</h2>
<blockquote>
<p>Less offers several extensions to the CSS <code>@import</code> CSS at-rule to provide more flexibility over what you can do with external files.</p>
</blockquote>
<p>Syntax: <code>@import (keyword) "filename";</code></p>
<p>The following import options have been implemented:</p>
<ul>
<li><code>reference</code>: use a Less file but do not output it</li>
<li><code>inline</code>: include the source file in the output but do not process it</li>
<li><code>less</code>: treat the file as a Less file, no matter what the file extension</li>
<li><code>css</code>: treat the file as a CSS file, no matter what the file extension</li>
<li><code>once</code>: only include the file once (this is default behavior)</li>
<li><code>multiple</code>: include the file multiple times</li>
<li><code>optional</code>: continue compiling when file is not found</li>
</ul>
<blockquote>
<p>More than one keyword per <code>@import</code> is allowed, you will have to use commas to separate the keywords:</p>
</blockquote>
<p>Example: <code>@import (optional, reference) "foo.less";</code></p>
<h3 id="import-atrules-feature-reference" class="docs-heading"><span class="anchor-target" id="import-atrules-feature-reference"></span>
<a href="#import-atrules-feature-reference" name="import-atrules-feature-reference" class="anchor glyphicon glyphicon-link"></a>reference</h3>
<p>Use <code>@import (reference)</code> to import external files, but without adding the imported styles to the compiled output unless referenced.</p>
<p>Released <a href="https://github.com/less/less.js/blob/master/CHANGELOG.md">v1.5.0</a></p>
<p>Example: <code>@import (reference) "foo.less";</code></p>
<p>Imagine that <code>reference</code> marks every at-rule and selector with a <em>reference flag</em> in the imported file, imports as normal, but when the CSS is generated, "reference" selectors (as well as any media queries containing only reference selectors) are not output. <code>reference</code> styles will not show up in your generated CSS unless the reference styles are used as <a href="#mixins-feature">mixins</a> or <a href="#extend-feature">extended</a>.</p>
<p>Additionally, <strong><code>reference</code></strong> produces different results depending on which method was used (mixin or extend):</p>
<ul>
<li><strong><a href="#extend-feature">extend</a></strong>: When a selector is extended, only the new selector is marked as <em>not referenced</em>, and it is pulled in at the position of the reference <code>@import</code> statement.</li>
<li><strong><a href="#mixins-feature">mixins</a></strong>: When a <code>reference</code> style is used as an <a href="#mixins-feature">implicit mixin</a>, its rules are mixed-in, marked "not reference", and appear in the referenced place as normal.</li>
</ul>
<h4 id="import-atrules-feature-reference-example" class="docs-heading"><span class="anchor-target" id="import-atrules-feature-reference-example"></span>
<a href="#import-atrules-feature-reference-example" name="import-atrules-feature-reference-example" class="anchor glyphicon glyphicon-link"></a>reference example</h4>
<p>This allows you to pull in only specific, targeted styles from a library such as <a href="https://github.com/twbs/bootstrap">Bootstrap</a> by doing something like this:</p>
<pre><code class="lang-less"><span class="hljs-class">.navbar</span><span class="hljs-keyword">:extend</span>(<span class="hljs-class">.navbar</span> <span class="hljs-keyword">all</span>) {}
</code></pre>
<p>And you will pull in only <code>.navbar</code> related styles from Bootstrap.</p>
<h3 id="import-atrules-feature-inline" class="docs-heading"><span class="anchor-target" id="import-atrules-feature-inline"></span>
<a href="#import-atrules-feature-inline" name="import-atrules-feature-inline" class="anchor glyphicon glyphicon-link"></a>inline</h3>
<p>Use <code>@import (inline)</code> to include external files, but not process them.</p>
<p>Released <a href="https://github.com/less/less.js/blob/master/CHANGELOG.md">v1.5.0</a></p>
<p>Example: <code>@import (inline) "not-less-compatible.css";</code></p>
<p>You will use this when a CSS file may not be Less compatible; this is because although Less supports most known standards CSS, it does not support comments in some places and does not support all known CSS hacks without modifying the CSS.</p>
<p>So you can use this to include the file in the output so that all CSS will be in one file.</p>
<h3 id="import-atrules-feature-less" class="docs-heading"><span class="anchor-target" id="import-atrules-feature-less"></span>
<a href="#import-atrules-feature-less" name="import-atrules-feature-less" class="anchor glyphicon glyphicon-link"></a>less</h3>
<p>Use <code>@import (less)</code> to treat imported files as Less, regardless of file extension.</p>
<p>Released <a href="https://github.com/less/less.js/blob/master/CHANGELOG.md">v1.4.0</a></p>
<p>Example:</p>
<pre><code class="lang-less"><span class="hljs-at_rule">@import</span> (less) <span class="hljs-string">"foo.css"</span>;
</code></pre>
<h3 id="import-atrules-feature-css" class="docs-heading"><span class="anchor-target" id="import-atrules-feature-css"></span>
<a href="#import-atrules-feature-css" name="import-atrules-feature-css" class="anchor glyphicon glyphicon-link"></a>css</h3>
<p>Use <code>@import (css)</code> to treat imported files as regular CSS, regardless of file extension. This means the import statement will be left as it is.</p>
<p>Released <a href="https://github.com/less/less.js/blob/master/CHANGELOG.md">v1.4.0</a></p>
<p>Example:</p>
<pre><code class="lang-less"><span class="hljs-at_rule">@import</span> (css) <span class="hljs-string">"foo.less"</span>;
</code></pre>
<p>outputs</p>
<pre><code class="lang-less"><span class="hljs-at_rule">@import</span> <span class="hljs-string">"foo.less"</span>;
</code></pre>
<h3 id="import-atrules-feature-once" class="docs-heading"><span class="anchor-target" id="import-atrules-feature-once"></span>
<a href="#import-atrules-feature-once" name="import-atrules-feature-once" class="anchor glyphicon glyphicon-link"></a>once</h3>
<p>The default behavior of <code>@import</code> statements. It means the file is imported only once and subsequent import statements for that file will be ignored.</p>
<p>Released <a href="https://github.com/less/less.js/blob/master/CHANGELOG.md">v1.4.0</a></p>
<p>This is the default behavior of <code>@import</code> statements.</p>
<p>Example:</p>
<pre><code class="lang-less"><span class="hljs-at_rule">@import</span> (once) <span class="hljs-string">"foo.less"</span>;
<span class="hljs-at_rule">@import</span> (once) <span class="hljs-string">"foo.less"</span>; <span class="hljs-comment">// this statement will be ignored</span>
</code></pre>
<h3 id="import-atrules-feature-multiple" class="docs-heading"><span class="anchor-target" id="import-atrules-feature-multiple"></span>
<a href="#import-atrules-feature-multiple" name="import-atrules-feature-multiple" class="anchor glyphicon glyphicon-link"></a>multiple</h3>
<p>Use <code>@import (multiple)</code> to allow importing of multiple files with the same name. This is the opposite behavior to once.</p>
<p>Released <a href="https://github.com/less/less.js/blob/master/CHANGELOG.md">v1.4.0</a></p>
<p>Example:</p>
<pre><code class="lang-less"><span class="hljs-comment">// file: foo.less</span>
<span class="hljs-class">.a</span> {
<span class="hljs-attribute">color</span>: green;
}
<span class="hljs-comment">// file: main.less</span>
<span class="hljs-at_rule">@import</span> (multiple) <span class="hljs-string">"foo.less"</span>;
<span class="hljs-at_rule">@import</span> (multiple) <span class="hljs-string">"foo.less"</span>;
</code></pre>
<p>Outputs</p>
<pre><code class="lang-less"><span class="hljs-class">.a</span> {
<span class="hljs-attribute">color</span>: green;
}
<span class="hljs-class">.a</span> {
<span class="hljs-attribute">color</span>: green;
}
</code></pre>
<h3 id="import-atrules-feature-optional" class="docs-heading"><span class="anchor-target" id="import-atrules-feature-optional"></span>
<a href="#import-atrules-feature-optional" name="import-atrules-feature-optional" class="anchor glyphicon glyphicon-link"></a>optional</h3>
<p>Use <code>@import (optional)</code> to allow importing of a file only when it exists. Without the <code>optional</code> keyword Less throws a FileError and stops compiling when importing a file that can not be found. </p>
<p>Released <a href="https://github.com/less/less.js/blob/master/CHANGELOG.md">v2.3.0</a></p>
<br>
</div>
</div>
<!-- Extend -->
<div class="docs-section">
<h1 id="extend-feature" class="docs-heading"><span class="anchor-target" id="extend-feature"></span>
<a href="#extend-feature" name="extend-feature" class="anchor glyphicon glyphicon-link"></a>Extend</h1>
<div class="section-content">
<a class="glyphicon glyphicon-pencil source-link right" href="https://github.com/less/less-docs/blob/master/content/features/extend.md" data-content="extendmd" target="_blank"></a>
<a id="extendmd" href="https://github.com/less/less-docs/blob/master/content/features/extend.md" target="_blank">Edit the markdown source for "extend"
<span class="glyphicon glyphicon-new-window"></span>
</a>
<!-- extend -->
<blockquote>
<p>Extend is a Less pseudo-class which merges the selector it is put on with ones that match what it references.</p>
</blockquote>
<p>Released <a href="https://github.com/less/less.js/blob/master/CHANGELOG.md">v1.4.0</a></p>
<pre><code class="lang-less"><span class="hljs-tag">nav</span> <span class="hljs-tag">ul</span> {
<span class="hljs-keyword">&</span><span class="hljs-keyword">:extend</span>(<span class="hljs-class">.inline</span>);
<span class="hljs-attribute">background</span>: blue;
}
</code></pre>
<p>In the rule set above, the <code>:extend</code> selector will apply the "extending selector" (<code>nav ul</code>) onto the <code>.inline</code> class <em>wherever the <code>.inline</code> class appears</em>. The declaration block will be kept as-is, but without any reference to the extend (because extend isn't css).</p>
<p>So the following:</p>
<pre><code class="lang-less"><span class="hljs-tag">nav</span> <span class="hljs-tag">ul</span> {
<span class="hljs-keyword">&</span><span class="hljs-keyword">:extend</span>(<span class="hljs-class">.inline</span>);
<span class="hljs-attribute">background</span>: blue;
}
<span class="hljs-class">.inline</span> {
<span class="hljs-attribute">color</span>: red;
}
</code></pre>
<p>Outputs</p>
<pre><code class="lang-css"><span class="hljs-tag">nav</span> <span class="hljs-tag">ul</span> {
<span class="hljs-attribute">background</span>: blue;
}
<span class="hljs-class">.inline</span>,
<span class="hljs-tag">nav</span> <span class="hljs-tag">ul</span> {
<span class="hljs-attribute">color</span>: red;
}
</code></pre>
<p>Notice how the <code>nav ul:extend(.inline)</code> selector gets output as <code>nav ul</code> - the extend gets removed before output and the selector block left as-is. If no properties are put in that block then it gets removed from the output (but the extend still may affect other selectors).</p>
<h3 id="extend-feature-extend-syntax" class="docs-heading"><span class="anchor-target" id="extend-feature-extend-syntax"></span>
<a href="#extend-feature-extend-syntax" name="extend-feature-extend-syntax" class="anchor glyphicon glyphicon-link"></a>Extend Syntax</h3>
<p>The extend is either attached to a selector or placed into a ruleset. It looks like a pseudo-class with selector parameter optionally followed by the keyword <code>all</code>:</p>
<p>Example:</p>
<pre><code class="lang-less"><span class="hljs-class">.a</span><span class="hljs-keyword">:extend</span>(<span class="hljs-class">.b</span>) {}
<span class="hljs-comment">// the above block does the same thing as the below block</span>
<span class="hljs-class">.a</span> {
<span class="hljs-keyword">&</span><span class="hljs-keyword">:extend</span>(<span class="hljs-class">.b</span>);
}
</code></pre>
<pre><code class="lang-less"><span class="hljs-class">.c</span><span class="hljs-keyword">:extend</span>(<span class="hljs-class">.d</span> <span class="hljs-keyword">all</span>) {
<span class="hljs-comment">// extends all instances of ".d" e.g. ".x.d" or ".d.x"</span>
}
<span class="hljs-class">.c</span><span class="hljs-keyword">:extend</span>(<span class="hljs-class">.d</span>) {
<span class="hljs-comment">// extends only instances where the selector will be output as just ".d"</span>
}
</code></pre>
<p>It can contain one or more classes to extend, separated by commas.</p>
<p>Example:</p>
<pre><code class="lang-less"><span class="hljs-class">.e</span><span class="hljs-keyword">:extend</span>(<span class="hljs-class">.f</span>) {}
<span class="hljs-class">.e</span><span class="hljs-keyword">:extend</span>(<span class="hljs-class">.g</span>) {}
<span class="hljs-comment">// the above and the below do the same thing</span>
<span class="hljs-class">.e</span><span class="hljs-keyword">:extend</span>(<span class="hljs-class">.f</span>, <span class="hljs-class">.g</span>) {}
</code></pre>
<h3 id="extend-feature-extend-attached-to-selector" class="docs-heading"><span class="anchor-target" id="extend-feature-extend-attached-to-selector"></span>
<a href="#extend-feature-extend-attached-to-selector" name="extend-feature-extend-attached-to-selector" class="anchor glyphicon glyphicon-link"></a>Extend Attached to Selector</h3>
<p>Extend attached to a selector looks like an ordinary pseudo-class with selector as a parameter. A selector can contain multiple extend clauses, but all extends must be at the end of the selector.</p>
<ul>
<li>Extend after the selector: <code>pre:hover:extend(div pre)</code>.</li>
<li>Space between selector and extend is allowed: <code>pre:hover :extend(div pre)</code>.</li>
<li>Multiple extends are allowed: <code>pre:hover:extend(div pre):extend(.bucket tr)</code> - Note this is the same as <code>pre:hover:extend(div pre, .bucket tr)</code></li>
<li>This is NOT allowed: <code>pre:hover:extend(div pre).nth-child(odd)</code>. Extend must be last.</li>
</ul>
<p>If a ruleset contains multiple selectors, any of them can have the extend keyword. Multiple selectors with extend in one ruleset:</p>
<pre><code class="lang-less"><span class="hljs-class">.big-division</span>,
<span class="hljs-class">.big-bag</span><span class="hljs-keyword">:extend</span>(<span class="hljs-class">.bag</span>),
<span class="hljs-class">.big-bucket</span><span class="hljs-keyword">:extend</span>(<span class="hljs-class">.bucket</span>) {
<span class="hljs-comment">// body</span>
}
</code></pre>
<h3 id="extend-feature-extend-inside-ruleset" class="docs-heading"><span class="anchor-target" id="extend-feature-extend-inside-ruleset"></span>
<a href="#extend-feature-extend-inside-ruleset" name="extend-feature-extend-inside-ruleset" class="anchor glyphicon glyphicon-link"></a>Extend Inside Ruleset</h3>
<p>Extend can be placed into a ruleset's body using <code>&:extend(selector)</code> syntax. Placing extend into a body is a shortcut for placing it into every single selector of that ruleset.</p>
<p>Extend inside a body:</p>
<pre><code class="lang-less"><span class="hljs-tag">pre</span><span class="hljs-pseudo">:hover</span>,
<span class="hljs-class">.some-class</span> {
<span class="hljs-keyword">&</span><span class="hljs-keyword">:extend</span>(<span class="hljs-tag">div</span> <span class="hljs-tag">pre</span>);
}
</code></pre>
<p>is exactly the same as adding an extend after each selector:</p>
<pre><code class="lang-less"><span class="hljs-tag">pre</span><span class="hljs-pseudo">:hover</span><span class="hljs-keyword">:extend</span>(<span class="hljs-tag">div</span> <span class="hljs-tag">pre</span>),
<span class="hljs-class">.some-class</span><span class="hljs-keyword">:extend</span>(<span class="hljs-tag">div</span> <span class="hljs-tag">pre</span>) {}
</code></pre>
<h3 id="extend-feature-extending-nested-selectors" class="docs-heading"><span class="anchor-target" id="extend-feature-extending-nested-selectors"></span>
<a href="#extend-feature-extending-nested-selectors" name="extend-feature-extending-nested-selectors" class="anchor glyphicon glyphicon-link"></a>Extending Nested Selectors</h3>
<p>Extend is able to match nested selectors. Following less:</p>
<p>Example:</p>
<pre><code class="lang-less"><span class="hljs-class">.bucket</span> {
<span class="hljs-tag">tr</span> { <span class="hljs-comment">// nested ruleset with target selector</span>
<span class="hljs-attribute">color</span>: blue;
}
}
<span class="hljs-class">.some-class</span><span class="hljs-keyword">:extend</span>(<span class="hljs-class">.bucket</span> <span class="hljs-tag">tr</span>) {} <span class="hljs-comment">// nested ruleset is recognized</span>
</code></pre>
<p>Outputs</p>
<pre><code class="lang-css"><span class="hljs-class">.bucket</span> <span class="hljs-tag">tr</span>,
<span class="hljs-class">.some-class</span> {
<span class="hljs-attribute">color</span>: blue;
}
</code></pre>
<p>Essentially the extend looks at the compiled css, not the original less.</p>
<p>Example:</p>
<pre><code class="lang-less"><span class="hljs-class">.bucket</span> {
<span class="hljs-tag">tr</span> <span class="hljs-keyword">&</span> { <span class="hljs-comment">// nested ruleset with target selector</span>
<span class="hljs-attribute">color</span>: blue;
}
}
<span class="hljs-class">.some-class</span><span class="hljs-keyword">:extend</span>(<span class="hljs-tag">tr</span> <span class="hljs-class">.bucket</span>) {} <span class="hljs-comment">// nested ruleset is recognized</span>
</code></pre>
<p>Outputs</p>
<pre><code class="lang-css"><span class="hljs-tag">tr</span> <span class="hljs-class">.bucket</span>,
<span class="hljs-class">.some-class</span> {
<span class="hljs-attribute">color</span>: blue;
}
</code></pre>
<h3 id="extend-feature-exact-matching-with-extend" class="docs-heading"><span class="anchor-target" id="extend-feature-exact-matching-with-extend"></span>
<a href="#extend-feature-exact-matching-with-extend" name="extend-feature-exact-matching-with-extend" class="anchor glyphicon glyphicon-link"></a>Exact Matching with Extend</h3>
<p>Extend by default looks for exact match between selectors. It does matter whether selector uses leading star or not. It does not matter that two nth-expressions have the same meaning, they need to have to same form in order to be matched. The only exception are quotes in attribute selector, less knows they have the same meaning and matches them.</p>
<p>Example:</p>
<pre><code class="lang-less"><span class="hljs-class">.a</span><span class="hljs-class">.class</span>,
<span class="hljs-class">.class</span><span class="hljs-class">.a</span>,
<span class="hljs-class">.class</span> > <span class="hljs-class">.a</span> {
<span class="hljs-attribute">color</span>: blue;
}
<span class="hljs-class">.test</span><span class="hljs-keyword">:extend</span>(<span class="hljs-class">.class</span>) {} <span class="hljs-comment">// this will NOT match the any selectors above</span>
</code></pre>
<p>Leading star does matter. Selectors <code>*.class</code> and <code>.class</code> are equivalent, but extend will not match them:</p>
<pre><code class="lang-less">*<span class="hljs-class">.class</span> {
<span class="hljs-attribute">color</span>: blue;
}
<span class="hljs-class">.noStar</span><span class="hljs-keyword">:extend</span>(<span class="hljs-class">.class</span>) {} <span class="hljs-comment">// this will NOT match the *.class selector</span>
</code></pre>
<p>Outputs</p>
<pre><code class="lang-css">*<span class="hljs-class">.class</span> {
<span class="hljs-attribute">color</span>: blue;
}
</code></pre>