How to do a For Each Item in an array in LESS css - Stack ...

文章推薦指數: 80 %
投票人數:10人

Loop through array of variable names in Less - Stack Overflow Home Public Questions Tags Users Companies Collectives ExploreCollectives Teams StackOverflowforTeams –Startcollaboratingandsharingorganizationalknowledge. CreateafreeTeam WhyTeams? Teams CreatefreeTeam Collectives™onStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. Learnmore Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. Learnmore HowtodoaForEachIteminanarrayinLESScss AskQuestion Asked 1year,11monthsago Modified 1year,10monthsago Viewed 129times 0 IhavingtroublewritingaforeachiteminLESScss Iamnewtousingless,ifsomeonecouldshowmeanexampleIwouldappreciateit Iamusingthefollowing: "less":"^3.11.3", "node-less-chokidar":"^0.4.1", "npm-run-all":"^4.1.5", @values:23,14,45; .as-test(@i:length(@a))when(@i>0){ @value:extract(@a,@i); .h-@{value}px{ height:~"@value"px; } .as-test-(@i-1); } .as-test(@values); desiredoutput: .h-23px{ height:23px!important; } .h-14px{ height:14px!important; } .h-45px{ height:45px!important; } cssless Share Improvethisquestion Follow askedJul8,2020at16:28 SeekingGuidanceSeekingGuidance 522bronzebadges Addacomment  |  2Answers 2 Sortedby: Resettodefault Highestscore(default) Datemodified(newestfirst) Datecreated(oldestfirst) 0 Usesomethinglikethis @values:23,14,45; .loop(@list,@i:1)when(@i<=length(@list)){ @current:extract(@list,@i)+0px; .h-@{current}{ height:@current!important; } .loop(@list,@i+1); } .loop(@values); Share Improvethisanswer Follow answeredJul11,2020at19:04 AKTAKT 80466silverbadges1616bronzebadges Addacomment  |  0 AnalternativetoAbhishekKumarTiwari's(validandworking)answer: @values:23,14,45; each(@values,{ .h-@{value}px{ height:unit(@value,px)!important; } }); Readmore:each(Less) Share Improvethisanswer Follow answeredJul15,2020at15:41 charlescharles 1,60411goldbadge1212silverbadges1919bronzebadges Addacomment  |  YourAnswer ThanksforcontributingananswertoStackOverflow!Pleasebesuretoanswerthequestion.Providedetailsandshareyourresearch!Butavoid…Askingforhelp,clarification,orrespondingtootheranswers.Makingstatementsbasedonopinion;backthemupwithreferencesorpersonalexperience.Tolearnmore,seeourtipsonwritinggreatanswers. Draftsaved Draftdiscarded Signuporlogin SignupusingGoogle SignupusingFacebook SignupusingEmailandPassword Submit Postasaguest Name Email Required,butnevershown PostYourAnswer Discard Byclicking“PostYourAnswer”,youagreetoourtermsofservice,privacypolicyandcookiepolicy Nottheansweryou'relookingfor?Browseotherquestionstaggedcsslessoraskyourownquestion. TheOverflowBlog Remoteworkiskillingbigoffices.Citiesmustchangetosurvive Onthequantuminternet,datadoesn’tstream;itteleports FeaturedonMeta AnnouncingthearrivalofValuedAssociate#1214:Dalmarus Improvementstositestatusandincidentcommunication CollectivesUpdate:IntroducingBulletins The[comma]tagisbeingburninated AskWizardTestResultsandNextSteps Related 1569 HowcanIverticallycenteradivelementforallbrowsersusingCSS? 2453 HowdoIgivetextoranimageatransparentbackgroundusingCSS? 1560 HowdoIstylea



請為這篇文章評分?