less.less 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662
  1. @nice-blue: #5B83AD;
  2. @light-blue: @nice-blue + #111;
  3. #header {
  4. color: @light-blue;
  5. }
  6. #header {
  7. color: #6c94be;
  8. }
  9. .bordered {
  10. border-top: dotted 1px black;
  11. border-bottom: solid 2px black;
  12. }
  13. #menu a {
  14. color: #111;
  15. .bordered;
  16. }
  17. .post a {
  18. color: red;
  19. .bordered;
  20. }
  21. #header {
  22. color: black;
  23. }
  24. #header .navigation {
  25. font-size: 12px;
  26. }
  27. #header .logo {
  28. width: 300px;
  29. }
  30. #header {
  31. color: black;
  32. .navigation {
  33. font-size: 12px;
  34. }
  35. .logo {
  36. width: 300px;
  37. }
  38. }
  39. .clearfix {
  40. display: block;
  41. zoom: 1;
  42. &:after {
  43. content: " ";
  44. display: block;
  45. font-size: 0;
  46. height: 0;
  47. clear: both;
  48. visibility: hidden;
  49. }
  50. }
  51. .screen-color {
  52. @media screen {
  53. color: green;
  54. @media (min-width: 768px) {
  55. color: red;
  56. }
  57. }
  58. @media tv {
  59. color: black;
  60. }
  61. }
  62. @media screen {
  63. .screen-color {
  64. color: green;
  65. }
  66. }
  67. @media screen and (min-width: 768px) {
  68. .screen-color {
  69. color: red;
  70. }
  71. }
  72. @media tv {
  73. .screen-color {
  74. color: black;
  75. }
  76. }
  77. #a {
  78. color: blue;
  79. @font-face {
  80. src: made-up-url;
  81. }
  82. padding: 2 2 2 2;
  83. }
  84. #a {
  85. color: blue;
  86. }
  87. @font-face {
  88. src: made-up-url;
  89. }
  90. #a {
  91. padding: 2 2 2 2;
  92. }
  93. // numbers are converted into the same units
  94. @conversion-1: 5cm + 10mm; // result is 6cm
  95. @conversion-2: 2 - 3cm - 5mm; // result is -1.5cm
  96. // conversion is impossible
  97. @incompatible-units: 2 + 5px - 3cm; // result is 4px
  98. // example with variables
  99. @base: 5%;
  100. @filler: @base * 2; // result is 10%
  101. @other: @base + @filler; // result is 15%
  102. @base: 2cm * 3mm; // result is 6cm
  103. @color: #224488 / 2; //results in #112244
  104. background-color: #112244 + #111; // result is #223355
  105. .weird-element {
  106. content: ~"^//* some horrible but needed css hack";
  107. }
  108. @base: #f04615;
  109. @width: 0.5;
  110. .class {
  111. width: percentage(@width); // returns `50%`
  112. color: saturate(@base, 5%);
  113. background-color: spin(lighten(@base, 25%), 8);
  114. }
  115. #bundle {
  116. .button {
  117. display: block;
  118. border: 1px solid black;
  119. background-color: grey;
  120. &:hover {
  121. background-color: white
  122. }
  123. }
  124. .tab { /* ... */ }
  125. .citation { /* ... */ }
  126. }
  127. #header a {
  128. color: orange;
  129. #bundle > .button;
  130. }
  131. @var: red;
  132. #page {
  133. @var: white;
  134. #header {
  135. color: @var; // white
  136. }
  137. }
  138. @var: red;
  139. #page {
  140. #header {
  141. color: @var; // white
  142. }
  143. @var: white;
  144. }
  145. /* One hell of a block
  146. style comment! */
  147. @var: red;
  148. // Get in line!
  149. @var: white;
  150. @import "library"; // library.less
  151. @import "typo.css";
  152. a,
  153. .link {
  154. color: #428bca;
  155. }
  156. .widget {
  157. color: #fff;
  158. background: #428bca;
  159. }
  160. // Variables
  161. @link-color: #428bca; // sea blue
  162. @link-color-hover: darken(@link-color, 10%);
  163. // Usage
  164. a,
  165. .link {
  166. color: @link-color;
  167. }
  168. a:hover {
  169. color: @link-color-hover;
  170. }
  171. .widget {
  172. color: #fff;
  173. background: @link-color;
  174. }
  175. // Variables
  176. @my-selector: banner;
  177. // Usage
  178. .@{my-selector} {
  179. font-weight: bold;
  180. line-height: 40px;
  181. margin: 0 auto;
  182. }
  183. .banner {
  184. font-weight: bold;
  185. line-height: 40px;
  186. margin: 0 auto;
  187. }
  188. // Variables
  189. @images: "../img";
  190. // Usage
  191. body {
  192. color: #444;
  193. background: url("@{images}/white-sand.png");
  194. }
  195. // Variables
  196. @themes: "../../src/themes";
  197. // Usage
  198. @import "@{themes}/tidal-wave.less";
  199. @property: color;
  200. .widget {
  201. @{property}: #0ee;
  202. background-@{property}: #999;
  203. }
  204. .widget {
  205. color: #0ee;
  206. background-color: #999;
  207. }
  208. @fnord: "I am fnord.";
  209. @var: "fnord";
  210. content: @@var;
  211. content: "I am fnord.";
  212. .lazy-eval {
  213. width: @var;
  214. }
  215. @var: @a;
  216. @a: 9%;
  217. .lazy-eval-scope {
  218. width: @var;
  219. @a: 9%;
  220. }
  221. @var: @a;
  222. @a: 100%;
  223. .lazy-eval-scope {
  224. width: 9%;
  225. }
  226. @var: 0;
  227. .class {
  228. @var: 1;
  229. .brass {
  230. @var: 2;
  231. three: @var;
  232. @var: 3;
  233. }
  234. one: @var;
  235. }
  236. .class {
  237. one: 1;
  238. }
  239. .class .brass {
  240. three: 3;
  241. }
  242. // library
  243. @base-color: green;
  244. @dark-color: darken(@base-color, 10%);
  245. // use of library
  246. @import "library.less";
  247. @base-color: red;
  248. nav ul {
  249. &:extend(.inline);
  250. background: blue;
  251. }
  252. nav ul {
  253. &:extend(.inline);
  254. background: blue;
  255. }
  256. .inline {
  257. color: red;
  258. }
  259. nav ul {
  260. background: blue;
  261. }
  262. .inline,
  263. nav ul {
  264. color: red;
  265. }
  266. .a:extend(.b) {}
  267. // the above block does the same thing as the below block
  268. .a {
  269. &:extend(.b);
  270. }
  271. .c:extend(.d all) {
  272. // extends all instances of ".d" e.g. ".x.d" or ".d.x"
  273. }
  274. .c:extend(.d) {
  275. // extends only instances where the selector will be output as just ".d"
  276. }
  277. .e:extend(.f) {}
  278. .e:extend(.g) {}
  279. // the above an the below do the same thing
  280. .e:extend(.f, .g) {}
  281. .big-division,
  282. .big-bag:extend(.bag),
  283. .big-bucket:extend(.bucket) {
  284. // body
  285. }
  286. pre:hover,
  287. .some-class {
  288. &:extend(div pre);
  289. }
  290. pre:hover:extend(div pre),
  291. .some-class:extend(div pre) {}
  292. .bucket {
  293. tr { // nested ruleset with target selector
  294. color: blue;
  295. }
  296. }
  297. .some-class:extend(.bucket tr) {} // nested ruleset is recognized
  298. .bucket tr,
  299. .some-class {
  300. color: blue;
  301. }
  302. .bucket {
  303. tr & { // nested ruleset with target selector
  304. color: blue;
  305. }
  306. }
  307. .some-class:extend(tr .bucket) {} // nested ruleset is recognized
  308. tr .bucket,
  309. .some-class {
  310. color: blue;
  311. }
  312. .a.class,
  313. .class.a,
  314. .class > .a {
  315. color: blue;
  316. }
  317. .test:extend(.class) {} // this will NOT match the any selectors above
  318. *.class {
  319. color: blue;
  320. }
  321. .noStar:extend(.class) {} // this will NOT match the *.class selector
  322. *.class {
  323. color: blue;
  324. }
  325. link:hover:visited {
  326. color: blue;
  327. }
  328. .selector:extend(link:visited:hover) {}
  329. link:hover:visited {
  330. color: blue;
  331. }
  332. :nth-child(1n+3) {
  333. color: blue;
  334. }
  335. .child:extend(:nth-child(n+3)) {}
  336. :nth-child(1n+3) {
  337. color: blue;
  338. }
  339. [title=identifier] {
  340. color: blue;
  341. }
  342. [title='identifier'] {
  343. color: blue;
  344. }
  345. [title="identifier"] {
  346. color: blue;
  347. }
  348. .noQuote:extend([title=identifier]) {}
  349. .singleQuote:extend([title='identifier']) {}
  350. .doubleQuote:extend([title="identifier"]) {}
  351. [title=identifier],
  352. .noQuote,
  353. .singleQuote,
  354. .doubleQuote {
  355. color: blue;
  356. }
  357. [title='identifier'],
  358. .noQuote,
  359. .singleQuote,
  360. .doubleQuote {
  361. color: blue;
  362. }
  363. [title="identifier"],
  364. .noQuote,
  365. .singleQuote,
  366. .doubleQuote {
  367. color: blue;
  368. }
  369. .a.b.test,
  370. .test.c {
  371. color: orange;
  372. }
  373. .test {
  374. &:hover {
  375. color: green;
  376. }
  377. }
  378. .replacement:extend(.test all) {}
  379. .a.b.test,
  380. .test.c,
  381. .a.b.replacement,
  382. .replacement.c {
  383. color: orange;
  384. }
  385. .test:hover,
  386. .replacement:hover {
  387. color: green;
  388. }
  389. @variable: .bucket;
  390. @{variable} { // interpolated selector
  391. color: blue;
  392. }
  393. .some-class:extend(.bucket) {} // does nothing, no match is found
  394. .bucket {
  395. color: blue;
  396. }
  397. .some-class:extend(@{variable}) {} // interpolated selector matches nothing
  398. @variable: .bucket;
  399. .bucket {
  400. color: blue;
  401. }
  402. .bucket {
  403. color: blue;
  404. }
  405. @{variable}:extend(.bucket) {}
  406. @variable: .selector;
  407. .bucket, .selector {
  408. color: blue;
  409. }
  410. @media print {
  411. .screenClass:extend(.selector) {} // extend inside media
  412. .selector { // this will be matched - it is in the same media
  413. color: black;
  414. }
  415. }
  416. .selector { // ruleset on top of style sheet - extend ignores it
  417. color: red;
  418. }
  419. @media screen {
  420. .selector { // ruleset inside another media - extend ignores it
  421. color: blue;
  422. }
  423. }
  424. @media print {
  425. .selector,
  426. .screenClass { /* ruleset inside the same media was extended */
  427. color: black;
  428. }
  429. }
  430. .selector { /* ruleset on top of style sheet was ignored */
  431. color: red;
  432. }
  433. @media screen {
  434. .selector { /* ruleset inside another media was ignored */
  435. color: blue;
  436. }
  437. }
  438. @media screen {
  439. .screenClass:extend(.selector) {} // extend inside media
  440. @media (min-width: 1023px) {
  441. .selector { // ruleset inside nested media - extend ignores it
  442. color: blue;
  443. }
  444. }
  445. }
  446. @media screen and (min-width: 1023px) {
  447. .selector { /* ruleset inside another nested media was ignored */
  448. color: blue;
  449. }
  450. }
  451. @media screen {
  452. .selector { /* ruleset inside nested media - top level extend works */
  453. color: blue;
  454. }
  455. @media (min-width: 1023px) {
  456. .selector { /* ruleset inside nested media - top level extend works */
  457. color: blue;
  458. }
  459. }
  460. }
  461. .topLevel:extend(.selector) {} /* top level extend matches everything */
  462. @media screen {
  463. .selector,
  464. .topLevel { /* ruleset inside media was extended */
  465. color: blue;
  466. }
  467. }
  468. @media screen and (min-width: 1023px) {
  469. .selector,
  470. .topLevel { /* ruleset inside nested media was extended */
  471. color: blue;
  472. }
  473. }
  474. .alert-info,
  475. .widget {
  476. /* declarations */
  477. }
  478. .alert:extend(.alert-info, .widget) {}
  479. .alert-info,
  480. .widget,
  481. .alert,
  482. .alert {
  483. /* declarations */
  484. }
  485. .animal {
  486. background-color: black;
  487. color: white;
  488. }
  489. .animal {
  490. background-color: black;
  491. color: white;
  492. }
  493. .bear {
  494. background-color: brown;
  495. }
  496. .animal {
  497. background-color: black;
  498. color: white;
  499. }
  500. .bear {
  501. &:extend(.animal);
  502. background-color: brown;
  503. }
  504. .my-inline-block() {
  505. display: inline-block;
  506. font-size: 0;
  507. }
  508. .thing1 {
  509. .my-inline-block;
  510. }
  511. .thing2 {
  512. .my-inline-block;
  513. }
  514. .thing1 {
  515. display: inline-block;
  516. font-size: 0;
  517. }
  518. .thing2 {
  519. display: inline-block;
  520. font-size: 0;
  521. }
  522. .my-inline-block {
  523. display: inline-block;
  524. font-size: 0;
  525. }
  526. .thing1 {
  527. &:extend(.my-inline-block);
  528. }
  529. .thing2 {
  530. &:extend(.my-inline-block);
  531. }
  532. .my-inline-block,
  533. .thing1,
  534. .thing2 {
  535. display: inline-block;
  536. font-size: 0;
  537. }
  538. li.list > a {
  539. // list styles
  540. }
  541. button.list-style {
  542. &:extend(li.list > a); // use the same list styles
  543. }
  544. .a, #b {
  545. color: red;
  546. }
  547. .mixin-class {
  548. .a();
  549. }
  550. .mixin-id {
  551. #b();
  552. }
  553. .a, #b {
  554. color: red;
  555. }
  556. .mixin-class {
  557. color: red;
  558. }
  559. .mixin-id {
  560. color: red;
  561. }
  562. // these two statements do the same thing:
  563. .a();
  564. .a;
  565. .my-mixin {
  566. color: black;
  567. }
  568. .my-other-mixin() {
  569. background: white;
  570. }
  571. .class {
  572. .my-mixin;
  573. .my-other-mixin;
  574. }
  575. .my-mixin {
  576. color: black;
  577. }
  578. .class {
  579. color: black;
  580. background: white;
  581. }
  582. .my-hover-mixin() {
  583. &:hover {
  584. border: 1px solid red;
  585. }
  586. }
  587. button {
  588. .my-hover-mixin();
  589. }
  590. button:hover {
  591. border: 1px solid red;
  592. }
  593. #outer {
  594. .inner {
  595. color: red;
  596. }
  597. }
  598. .c {
  599. #outer > .inner;
  600. }
  601. // all do the same thing
  602. #outer > .inner;
  603. #outer > .inner();
  604. #outer .inner;
  605. #outer .inner();
  606. #outer.inner;
  607. #outer.inner();
  608. #my-library {
  609. .my-mixin() {
  610. color: black;
  611. }
  612. }
  613. // which can be used like this
  614. .class {
  615. #my-library > .my-mixin();
  616. }
  617. #namespace when (@mode=huge) {
  618. .mixin() { /* */ }
  619. }
  620. #namespace {
  621. .mixin() when (@mode=huge) { /* */ }
  622. }
  623. #sp_1 when (default()) {
  624. #sp_2 when (default()) {
  625. .mixin() when not(default()) { /* */ }
  626. }
  627. }
  628. .foo (@bg: #f5f5f5, @color: #900) {
  629. background: @bg;
  630. color: @color;
  631. }
  632. .unimportant {
  633. .foo();
  634. }
  635. .important {
  636. .foo() !important;
  637. }
  638. .unimportant {
  639. background: #f5f5f5;
  640. color: #900;
  641. }
  642. .important {
  643. background: #f5f5f5 !important;
  644. color: #900 !important;
  645. }
  646. .border-radius(@radius) {
  647. -webkit-border-radius: @radius;
  648. -moz-border-radius: @radius;
  649. border-radius: @radius;
  650. }
  651. #header {
  652. .border-radius(4px);
  653. }
  654. .button {
  655. .border-radius(6px);
  656. }
  657. .border-radius(@radius: 5px) {
  658. -webkit-border-radius: @radius;
  659. -moz-border-radius: @radius;
  660. border-radius: @radius;
  661. }
  662. #header {
  663. .border-radius;
  664. }
  665. .wrap() {
  666. text-wrap: wrap;
  667. white-space: -moz-pre-wrap;
  668. white-space: pre-wrap;
  669. word-wrap: break-word;
  670. }
  671. pre { .wrap }
  672. pre {
  673. text-wrap: wrap;
  674. white-space: -moz-pre-wrap;
  675. white-space: pre-wrap;
  676. word-wrap: break-word;
  677. }
  678. .mixin(@color) {
  679. color-1: @color;
  680. }
  681. .mixin(@color; @padding: 2) {
  682. color-2: @color;
  683. padding-2: @padding;
  684. }
  685. .mixin(@color; @padding; @margin: 2) {
  686. color-3: @color;
  687. padding-3: @padding;
  688. margin: @margin @margin @margin @margin;
  689. }
  690. .some .selector div {
  691. .mixin(#008000);
  692. }
  693. .some .selector div {
  694. color-1: #008000;
  695. color-2: #008000;
  696. padding-2: 2;
  697. }
  698. .mixin(@color: black; @margin: 10px; @padding: 20px) {
  699. color: @color;
  700. margin: @margin;
  701. padding: @padding;
  702. }
  703. .class1 {
  704. .mixin(@margin: 20px; @color: #33acfe);
  705. }
  706. .class2 {
  707. .mixin(#efca44; @padding: 40px);
  708. }
  709. .class1 {
  710. color: #33acfe;
  711. margin: 20px;
  712. padding: 20px;
  713. }
  714. .class2 {
  715. color: #efca44;
  716. margin: 10px;
  717. padding: 40px;
  718. }
  719. .box-shadow(@x: 0; @y: 0; @blur: 1px; @color: #000) {
  720. -webkit-box-shadow: @arguments;
  721. -moz-box-shadow: @arguments;
  722. box-shadow: @arguments;
  723. }
  724. .big-block {
  725. .box-shadow(2px; 5px);
  726. }
  727. .big-block {
  728. -webkit-box-shadow: 2px 5px 1px #000;
  729. -moz-box-shadow: 2px 5px 1px #000;
  730. box-shadow: 2px 5px 1px #000;
  731. }
  732. .mixin(/* ... */) {} // matches 0-N arguments
  733. .mixin() {} // matches exactly 0 arguments
  734. .mixin(@a: 1) {} // matches 0-1 arguments
  735. .mixin(@a: 1; /* ... */) {} // matches 0-N arguments
  736. .mixin(@a; /* ... */) {} // matches 1-N arguments
  737. .mixin(@a; @rest...) {
  738. // @rest is bound to arguments after @a
  739. // @arguments is bound to all arguments
  740. }
  741. .mixin(@s; @color) { /* ... */ }
  742. .class {
  743. .mixin(@switch; #888);
  744. }
  745. .mixin(dark; @color) {
  746. color: darken(@color, 10%);
  747. }
  748. .mixin(light; @color) {
  749. color: lighten(@color, 10%);
  750. }
  751. .mixin(@_; @color) {
  752. display: block;
  753. }
  754. @switch: light;
  755. .class {
  756. .mixin(@switch; #888);
  757. }
  758. .class {
  759. color: #a2a2a2;
  760. display: block;
  761. }
  762. .mixin(@a) {
  763. color: @a;
  764. }
  765. .mixin(@a; @b) {
  766. color: fade(@a; @b);
  767. }
  768. .mixin() {
  769. @width: 100%;
  770. @height: 200px;
  771. }
  772. .caller {
  773. .mixin();
  774. width: @width;
  775. height: @height;
  776. }
  777. .caller {
  778. width: 100%;
  779. height: 200px;
  780. }
  781. .average(@x, @y) {
  782. @average: ((@x + @y) / 2);
  783. }
  784. div {
  785. .average(16px, 50px); // "call" the mixin
  786. padding: @average; // use its "return" value
  787. }
  788. div {
  789. padding: 33px;
  790. }
  791. .mixin() {
  792. @size: in-mixin;
  793. @definedOnlyInMixin: in-mixin;
  794. }
  795. .class {
  796. margin: @size @definedOnlyInMixin;
  797. .mixin();
  798. }
  799. @size: globally-defined-value; // callers parent scope - no protection
  800. .class {
  801. margin: in-mixin in-mixin;
  802. }
  803. .unlock(@value) { // outer mixin
  804. .doSomething() { // nested mixin
  805. declaration: @value;
  806. }
  807. }
  808. #namespace {
  809. .unlock(5); // unlock doSomething mixin
  810. .doSomething(); //nested mixin was copied here and is usable
  811. }
  812. #namespace {
  813. declaration: 5;
  814. }
  815. // declare detached ruleset
  816. @detached-ruleset: { background: red; };
  817. // use detached ruleset
  818. .top {
  819. @detached-ruleset();
  820. }
  821. .top {
  822. background: red;
  823. }
  824. .desktop-and-old-ie(@rules) {
  825. @media screen and (min-width: 1200px) { @rules(); }
  826. html.lt-ie9 & { @rules(); }
  827. }
  828. header {
  829. background-color: blue;
  830. .desktop-and-old-ie({
  831. background-color: red;
  832. });
  833. }
  834. header {
  835. background-color: blue;
  836. }
  837. @media screen and (min-width: 1200px) {
  838. header {
  839. background-color: red;
  840. }
  841. }
  842. html.lt-ie9 header {
  843. background-color: red;
  844. }
  845. @my-ruleset: {
  846. .my-selector {
  847. background-color: black;
  848. }
  849. };
  850. @my-ruleset: {
  851. .my-selector {
  852. @media tv {
  853. background-color: black;
  854. }
  855. }
  856. };
  857. @media (orientation:portrait) {
  858. @my-ruleset();
  859. }
  860. @media (orientation: portrait) and tv {
  861. .my-selector {
  862. background-color: black;
  863. }
  864. }
  865. // detached ruleset with a mixin
  866. @detached-ruleset: {
  867. .mixin() {
  868. color:blue;
  869. }
  870. };
  871. // call detached ruleset
  872. .caller {
  873. @detached-ruleset();
  874. .mixin();
  875. }
  876. .caller {
  877. color: blue;
  878. }
  879. @detached-ruleset: {
  880. @color:blue; // this variable is private
  881. };
  882. .caller {
  883. color: @color; // syntax error
  884. }
  885. @detached-ruleset: {
  886. caller-variable: @caller-variable; // variable is undefined here
  887. .caller-mixin(); // mixin is undefined here
  888. };
  889. selector {
  890. // use detached ruleset
  891. @detached-ruleset();
  892. // define variable and mixin needed inside the detached ruleset
  893. @caller-variable: value;
  894. .caller-mixin() {
  895. variable: declaration;
  896. }
  897. }
  898. selector {
  899. caller-variable: value;
  900. variable: declaration;
  901. }
  902. @variable: global;
  903. @detached-ruleset: {
  904. // will use global variable, because it is accessible
  905. // from detached-ruleset definition
  906. variable: @variable;
  907. };
  908. selector {
  909. @detached-ruleset();
  910. @variable: value; // variable defined in caller - will be ignored
  911. }
  912. selector {
  913. variable: global;
  914. }
  915. @detached-1: { scope-detached: @one @two; };
  916. .one {
  917. @one: visible;
  918. .two {
  919. @detached-2: @detached-1; // copying/renaming ruleset
  920. @two: visible; // ruleset can not see this variable
  921. }
  922. }
  923. .use-place {
  924. .one > .two();
  925. @detached-2();
  926. }
  927. #space {
  928. .importer-1() {
  929. @detached: { scope-detached: @variable; }; // define detached ruleset
  930. }
  931. }
  932. .importer-2() {
  933. @variable: value; // unlocked detached ruleset CAN see this variable
  934. #space > .importer-1(); // unlock/import detached ruleset
  935. }
  936. .use-place {
  937. .importer-2(); // unlock/import detached ruleset second time
  938. @detached();
  939. }
  940. .use-place {
  941. scope-detached: value;
  942. }
  943. @my-ruleset:{.my-selector{@media tv{background-color:black;}}};
  944. .foo {
  945. background: #900;
  946. }
  947. @import "this-is-valid.less";
  948. @import "foo"; // foo.less is imported
  949. @import "foo.less"; // foo.less is imported
  950. @import "foo.php"; // foo.php imported as a less file
  951. @import "foo.css"; // statement left in place, as-is
  952. .navbar:extend(.navbar all) {}
  953. @import (less) "foo.css";
  954. @import (css) "foo.less";
  955. @import "foo.less";
  956. @import (once) "foo.less";
  957. @import (once) "foo.less"; // this statement will be ignored
  958. // file: foo.less
  959. .a {
  960. color: green;
  961. }
  962. // file: main.less
  963. @import (multiple) "foo.less";
  964. @import (multiple) "foo.less";
  965. .a {
  966. color: green;
  967. }
  968. .a {
  969. color: green;
  970. }
  971. .mixin (@a) when (lightness(@a) >= 50%) {
  972. background-color: black;
  973. }
  974. .mixin (@a) when (lightness(@a) < 50%) {
  975. background-color: white;
  976. }
  977. .mixin (@a) {
  978. color: @a;
  979. }
  980. .class1 { .mixin(#ddd) }
  981. .class2 { .mixin(#555) }
  982. .class1 {
  983. background-color: black;
  984. color: #ddd;
  985. }
  986. .class2 {
  987. background-color: white;
  988. color: #555;
  989. }
  990. .truth (@a) when (@a) { /* ... */ }
  991. .truth (@a) when (@a = true) { /* ... */ }
  992. .class {
  993. .truth(40); // Will not match any of the above definitions.
  994. }
  995. @media: mobile;
  996. .mixin (@a) when (@media = mobile) { /* ... */ }
  997. .mixin (@a) when (@media = desktop) { /* ... */ }
  998. .max (@a; @b) when (@a > @b) { width: @a }
  999. .max (@a; @b) when (@a < @b) { width: @b }
  1000. .mixin (@a) when (isnumber(@a)) and (@a > 0) { /* ... */ }
  1001. .mixin (@a) when (@a > 10), (@a < -10) { /* ... */ }
  1002. .mixin (@b) when not (@b > 0) { /* ... */ }
  1003. .mixin (@a; @b: 0) when (isnumber(@b)) { /* ... */ }
  1004. .mixin (@a; @b: black) when (iscolor(@b)) { /* ... */ }
  1005. .mixin (@a) when (@a > 0) { /* ... */ }
  1006. .mixin (@a) when (default()) { /* ... */ } // matches only if first mixin does not, i.e. when @a <= 0
  1007. .my-optional-style() when (@my-option = true) {
  1008. button {
  1009. color: white;
  1010. }
  1011. }
  1012. .my-optional-style();
  1013. button when (@my-option = true) {
  1014. color: white;
  1015. }
  1016. & when (@my-option = true) {
  1017. button {
  1018. color: white;
  1019. }
  1020. a {
  1021. color: blue;
  1022. }
  1023. }
  1024. .loop(@counter) when (@counter > 0) {
  1025. .loop((@counter - 1)); // next iteration
  1026. width: (10px * @counter); // code for each iteration
  1027. }
  1028. div {
  1029. .loop(5); // launch the loop
  1030. }
  1031. div {
  1032. width: 10px;
  1033. width: 20px;
  1034. width: 30px;
  1035. width: 40px;
  1036. width: 50px;
  1037. }
  1038. .generate-columns(4);
  1039. .generate-columns(@n, @i: 1) when (@i =< @n) {
  1040. .column-@{i} {
  1041. width: (@i * 100% / @n);
  1042. }
  1043. .generate-columns(@n, (@i + 1));
  1044. }
  1045. .column-1 {
  1046. width: 25%;
  1047. }
  1048. .column-2 {
  1049. width: 50%;
  1050. }
  1051. .column-3 {
  1052. width: 75%;
  1053. }
  1054. .column-4 {
  1055. width: 100%;
  1056. }
  1057. .mixin() {
  1058. box-shadow+: inset 0 0 10px #555;
  1059. }
  1060. .myclass {
  1061. .mixin();
  1062. box-shadow+: 0 0 20px black;
  1063. }
  1064. .myclass {
  1065. box-shadow: inset 0 0 10px #555, 0 0 20px black;
  1066. }
  1067. .mixin() {
  1068. transform+_: scale(2);
  1069. }
  1070. .myclass {
  1071. .mixin();
  1072. transform+_: rotate(15deg);
  1073. }
  1074. .myclass {
  1075. transform: scale(2) rotate(15deg);
  1076. }
  1077. a {
  1078. color: blue;
  1079. &:hover {
  1080. color: green;
  1081. }
  1082. }
  1083. a {
  1084. color: blue;
  1085. }
  1086. a:hover {
  1087. color: green;
  1088. }
  1089. .button {
  1090. &-ok {
  1091. background-image: url("ok.png");
  1092. }
  1093. &-cancel {
  1094. background-image: url("cancel.png");
  1095. }
  1096. &-custom {
  1097. background-image: url("custom.png");
  1098. }
  1099. }
  1100. .button-ok {
  1101. background-image: url("ok.png");
  1102. }
  1103. .button-cancel {
  1104. background-image: url("cancel.png");
  1105. }
  1106. .button-custom {
  1107. background-image: url("custom.png");
  1108. }
  1109. .link {
  1110. & + & {
  1111. color: red;
  1112. }
  1113. & & {
  1114. color: green;
  1115. }
  1116. && {
  1117. color: blue;
  1118. }
  1119. &, &ish {
  1120. color: cyan;
  1121. }
  1122. }
  1123. .link + .link {
  1124. color: red;
  1125. }
  1126. .link .link {
  1127. color: green;
  1128. }
  1129. .link.link {
  1130. color: blue;
  1131. }
  1132. .link, .linkish {
  1133. color: cyan;
  1134. }
  1135. .grand {
  1136. .parent {
  1137. & > & {
  1138. color: red;
  1139. }
  1140. & & {
  1141. color: green;
  1142. }
  1143. && {
  1144. color: blue;
  1145. }
  1146. &, &ish {
  1147. color: cyan;
  1148. }
  1149. }
  1150. }
  1151. .grand .parent > .grand .parent {
  1152. color: red;
  1153. }
  1154. .grand .parent .grand .parent {
  1155. color: green;
  1156. }
  1157. .grand .parent.grand .parent {
  1158. color: blue;
  1159. }
  1160. .grand .parent,
  1161. .grand .parentish {
  1162. color: cyan;
  1163. }
  1164. .header {
  1165. .menu {
  1166. border-radius: 5px;
  1167. .no-borderradius & {
  1168. background-image: url('images/button-background.png');
  1169. }
  1170. }
  1171. }
  1172. .header .menu {
  1173. border-radius: 5px;
  1174. }
  1175. .no-borderradius .header .menu {
  1176. background-image: url('images/button-background.png');
  1177. }
  1178. p, a, ul, li {
  1179. border-top: 2px dotted #366;
  1180. & + & {
  1181. border-top: 0;
  1182. }
  1183. }
  1184. p,
  1185. a,
  1186. ul,
  1187. li {
  1188. border-top: 2px dotted #366;
  1189. }
  1190. p + p,
  1191. p + a,
  1192. p + ul,
  1193. p + li,
  1194. a + p,
  1195. a + a,
  1196. a + ul,
  1197. a + li,
  1198. ul + p,
  1199. ul + a,
  1200. ul + ul,
  1201. ul + li,
  1202. li + p,
  1203. li + a,
  1204. li + ul,
  1205. li + li {
  1206. border-top: 0;
  1207. }
  1208. .foobar {
  1209. &:extend(.foo);
  1210. }
  1211. .thing {
  1212. &:hover {
  1213. background-color: blue;
  1214. .thing-child {}
  1215. }
  1216. }
  1217. .foo,
  1218. // Comment
  1219. .bar {
  1220. // Comment
  1221. color: red; // Comment
  1222. }
  1223. // Variables
  1224. @link-color: #428bca; // Comment
  1225. [href]:hover &, // Comment
  1226. [href]:focus &, // Comment
  1227. [href]:active & {
  1228. .tooltip {
  1229. opacity: 1;
  1230. }
  1231. }
  1232. // Usage
  1233. @import // Comment
  1234. "@{themes}/tidal-wave.less";