less Tutorial => Writing a for-each loop
文章推薦指數: 80 %
Learn less - Writing a for-each loop. ... A for-each loop in Less has the same key components as a for loop except for the following ... Compiled CSS: Downloadless(PDF) less Gettingstartedwithless ColorOperationFunctions Extend Guards(forwritingconditionalmixins) Loops Writingasimpleforloop Writingafor-eachloop Mixins Parentselectors Variables less Gettingstartedwithless ColorOperationFunctions Extend Guards(forwritingconditionalmixins) Loops Writingasimpleforloop Writingafor-eachloop Mixins Parentselectors Variables less Loops Writingafor-eachloop Example Afor-eachloopinLesshasthesamekeycomponentsasaforloopexceptforthefollowingdifferences: Avariablewhichcontainsthelistofitemsthathastobeiteratedover. Anextract()functiontoextracteachiteminthevariablebasedontheloop'sindex. Alength()functiontocalculatethelengthofthearray(thatis,thenoofitemsinthelist)anduseitintheprimarymixincall(for[initialization]). Belowisasamplefor-eachloopwritteninLessthatiteratesthrougheachiteminthe@imagesvariable,createsa#idselectorwheretheidisthesameastheitem/imagenameandalsosetsthebackgroundimagepropertyforit. @images:cat,dog,apple,orange;/*thearraylistofitems*/ .for-each-loop(@index)when(@index>0){/*recursivemixincallwithguard-condition*/ @image:extract(@images,@index);/*extractfunctiontofetcheachitemfromthelist*/ /*thestatement*/ #@{image}{ background-image:url("http://mysite.com/@{image}.png"); } /*endofthestatement*/ .for-each-loop(@index-1);/*thenextiteration'scall-final-expression*/ } .for-loop(length(@images));/*theprimarycallwithlength()function-initialization*/ CompiledCSS: #orange{ background-image:url("http://mysite.com/orange.png"); } #apple{ background-image:url("http://mysite.com/apple.png"); } #dog{ background-image:url("http://mysite.com/dog.png"); } #cat{ background-image:url("http://mysite.com/cat.png"); } PDF-Downloadlessforfree Previous Next ThismodifiedtextisanextractoftheoriginalStackOverflowDocumentationcreatedbyfollowingcontributorsandreleasedunderCCBY-SA3.0 ThiswebsiteisnotaffiliatedwithStackOverflow SUPPORT&PARTNERS Advertisewithus Contactus PrivacyPolicy STAYCONNECTED Getmonthlyupdatesaboutnewarticles,cheatsheets,andtricks. Subscribe
延伸文章資訊
- 1用LESS 寫CSS ( 判斷式、迴圈、Function )
經過前兩篇的洗禮,應該可以直接用LESS 來撰寫整個網站的CSS 了,不過如果要針對大型的專案,在樣式的規劃上可能就要用到更進階的設定,第三篇的LESS 文章將會介紹一些 ...
- 2CSS, SCSS, and Less support in Visual Studio Code
Go to Declaration and Find References#. This is supported for Sass and Less variables in the same...
- 3less Tutorial => Writing a for-each loop
Learn less - Writing a for-each loop. ... A for-each loop in Less has the same key components as ...
- 4Functions | Less.js
Less extends CSS with dynamic behavior such as variables, mixins, operations and functions. Less ...
- 5LESS CSS - Beginner's Guide - Hongkiat
It ships plain CSS with programming traits such as Variables, Functions or Mixin, ... LESS syntax...