A place to cache linked articles (think custom and personal wayback machine)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.html 252KB

4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881
  1. <!doctype html><!-- This is a valid HTML5 document. -->
  2. <!-- Screen readers, SEO, extensions and so on. -->
  3. <html lang=fr>
  4. <!-- Has to be within the first 1024 bytes, hence before the <title>
  5. See: https://www.w3.org/TR/2012/CR-html5-20121217/document-metadata.html#charset -->
  6. <meta charset=utf-8>
  7. <!-- Why no `X-UA-Compatible` meta: https://stackoverflow.com/a/6771584 -->
  8. <!-- The viewport meta is quite crowded and we are responsible for that.
  9. See: https://codepen.io/tigt/post/meta-viewport-for-2015 -->
  10. <meta name=viewport content="width=device-width,minimum-scale=1,initial-scale=1,shrink-to-fit=no">
  11. <!-- Required to make a valid HTML5 document. -->
  12. <title>Sass Guidelines (archive) — David Larlet</title>
  13. <!-- Generated from https://realfavicongenerator.net/ such a mess. -->
  14. <link rel="apple-touch-icon" sizes="180x180" href="/static/david/icons/apple-touch-icon.png">
  15. <link rel="icon" type="image/png" sizes="32x32" href="/static/david/icons/favicon-32x32.png">
  16. <link rel="icon" type="image/png" sizes="16x16" href="/static/david/icons/favicon-16x16.png">
  17. <link rel="manifest" href="/manifest.json">
  18. <link rel="mask-icon" href="/static/david/icons/safari-pinned-tab.svg" color="#5bbad5">
  19. <link rel="shortcut icon" href="/static/david/icons/favicon.ico">
  20. <meta name="apple-mobile-web-app-title" content="David Larlet">
  21. <meta name="application-name" content="David Larlet">
  22. <meta name="msapplication-TileColor" content="#da532c">
  23. <meta name="msapplication-config" content="/static/david/icons/browserconfig.xml">
  24. <meta name="theme-color" content="#f0f0ea">
  25. <!-- That good ol' feed, subscribe :p. -->
  26. <link rel=alternate type="application/atom+xml" title=Feed href="/david/log/">
  27. <meta name="robots" content="noindex, nofollow">
  28. <meta content="origin-when-cross-origin" name="referrer">
  29. <!-- Canonical URL for SEO purposes -->
  30. <link rel="canonical" href="http://sass-guidelin.es/">
  31. <style>
  32. /* http://meyerweb.com/eric/tools/css/reset/ */
  33. html, body, div, span,
  34. h1, h2, h3, h4, h5, h6, p, blockquote, pre,
  35. a, abbr, address, big, cite, code,
  36. del, dfn, em, img, ins,
  37. small, strike, strong, tt, var,
  38. dl, dt, dd, ol, ul, li,
  39. fieldset, form, label, legend,
  40. table, caption, tbody, tfoot, thead, tr, th, td,
  41. article, aside, canvas, details, embed,
  42. figure, figcaption, footer, header, hgroup,
  43. menu, nav, output, ruby, section, summary,
  44. time, mark, audio, video {
  45. margin: 0;
  46. padding: 0;
  47. border: 0;
  48. font-size: 100%;
  49. font: inherit;
  50. vertical-align: baseline;
  51. }
  52. /* HTML5 display-role reset for older browsers */
  53. article, aside, details, figcaption, figure,
  54. footer, header, hgroup, menu, nav, section { display: block; }
  55. body { line-height: 1; }
  56. blockquote, q { quotes: none; }
  57. blockquote:before, blockquote:after,
  58. q:before, q:after {
  59. content: '';
  60. content: none;
  61. }
  62. table {
  63. border-collapse: collapse;
  64. border-spacing: 0;
  65. }
  66. /* http://practicaltypography.com/equity.html */
  67. /* https://calendar.perfplanet.com/2016/no-font-face-bulletproof-syntax/ */
  68. /* https://www.filamentgroup.com/lab/js-web-fonts.html */
  69. @font-face {
  70. font-family: 'EquityTextB';
  71. src: url('/static/david/css/fonts/Equity-Text-B-Regular-webfont.woff2') format('woff2'),
  72. url('/static/david/css/fonts/Equity-Text-B-Regular-webfont.woff') format('woff');
  73. font-weight: 300;
  74. font-style: normal;
  75. font-display: swap;
  76. }
  77. @font-face {
  78. font-family: 'EquityTextB';
  79. src: url('/static/david/css/fonts/Equity-Text-B-Italic-webfont.woff2') format('woff2'),
  80. url('/static/david/css/fonts/Equity-Text-B-Italic-webfont.woff') format('woff');
  81. font-weight: 300;
  82. font-style: italic;
  83. font-display: swap;
  84. }
  85. @font-face {
  86. font-family: 'EquityTextB';
  87. src: url('/static/david/css/fonts/Equity-Text-B-Bold-webfont.woff2') format('woff2'),
  88. url('/static/david/css/fonts/Equity-Text-B-Bold-webfont.woff') format('woff');
  89. font-weight: 700;
  90. font-style: normal;
  91. font-display: swap;
  92. }
  93. @font-face {
  94. font-family: 'ConcourseT3';
  95. src: url('/static/david/css/fonts/concourse_t3_regular-webfont-20190806.woff2') format('woff2'),
  96. url('/static/david/css/fonts/concourse_t3_regular-webfont-20190806.woff') format('woff');
  97. font-weight: 300;
  98. font-style: normal;
  99. font-display: swap;
  100. }
  101. /* http://practice.typekit.com/lesson/caring-about-opentype-features/ */
  102. body {
  103. /* http://www.cssfontstack.com/ Palatino 99% Win 86% Mac */
  104. font-family: "EquityTextB", Palatino, serif;
  105. background-color: #f0f0ea;
  106. color: #07486c;
  107. font-kerning: normal;
  108. -moz-osx-font-smoothing: grayscale;
  109. -webkit-font-smoothing: subpixel-antialiased;
  110. text-rendering: optimizeLegibility;
  111. font-variant-ligatures: common-ligatures contextual;
  112. font-feature-settings: "kern", "liga", "clig", "calt";
  113. }
  114. pre, code, kbd, samp, var, tt {
  115. font-family: 'TriplicateT4c', monospace;
  116. }
  117. em {
  118. font-style: italic;
  119. color: #323a45;
  120. }
  121. strong {
  122. font-weight: bold;
  123. color: black;
  124. }
  125. nav {
  126. background-color: #323a45;
  127. color: #f0f0ea;
  128. display: flex;
  129. justify-content: space-around;
  130. padding: 1rem .5rem;
  131. }
  132. nav:last-child {
  133. border-bottom: 1vh solid #2d7474;
  134. }
  135. nav a {
  136. color: #f0f0ea;
  137. }
  138. nav abbr {
  139. border-bottom: 1px dotted white;
  140. }
  141. h1 {
  142. border-top: 1vh solid #2d7474;
  143. border-bottom: .2vh dotted #2d7474;
  144. background-color: #e3e1e1;
  145. color: #323a45;
  146. text-align: center;
  147. padding: 5rem 0 4rem 0;
  148. width: 100%;
  149. font-family: 'ConcourseT3';
  150. display: flex;
  151. flex-direction: column;
  152. }
  153. h1.single {
  154. padding-bottom: 10rem;
  155. }
  156. h1 span {
  157. position: absolute;
  158. top: 1vh;
  159. left: 20%;
  160. line-height: 0;
  161. }
  162. h1 span a {
  163. line-height: 1.7;
  164. padding: 1rem 1.2rem .6rem 1.2rem;
  165. border-radius: 0 0 6% 6%;
  166. background: #2d7474;
  167. font-size: 1.3rem;
  168. color: white;
  169. text-decoration: none;
  170. }
  171. h2 {
  172. margin: 4rem 0 1rem;
  173. border-top: .2vh solid #2d7474;
  174. padding-top: 1vh;
  175. }
  176. h3 {
  177. text-align: center;
  178. margin: 3rem 0 .75em;
  179. }
  180. hr {
  181. height: .4rem;
  182. width: .4rem;
  183. border-radius: .4rem;
  184. background: #07486c;
  185. margin: 2.5rem auto;
  186. }
  187. time {
  188. display: bloc;
  189. margin-left: 0 !important;
  190. }
  191. ul, ol {
  192. margin: 2rem;
  193. }
  194. ul {
  195. list-style-type: square;
  196. }
  197. a {
  198. text-decoration-skip-ink: auto;
  199. text-decoration-thickness: 0.05em;
  200. text-underline-offset: 0.09em;
  201. }
  202. article {
  203. max-width: 50rem;
  204. display: flex;
  205. flex-direction: column;
  206. margin: 2rem auto;
  207. }
  208. article.single {
  209. border-top: .2vh dotted #2d7474;
  210. margin: -6rem auto 1rem auto;
  211. background: #f0f0ea;
  212. padding: 2rem;
  213. }
  214. article p:last-child {
  215. margin-bottom: 1rem;
  216. }
  217. p {
  218. padding: 0 .5rem;
  219. margin-left: 3rem;
  220. }
  221. p + p,
  222. figure + p {
  223. margin-top: 2rem;
  224. }
  225. blockquote {
  226. background-color: #e3e1e1;
  227. border-left: .5vw solid #2d7474;
  228. display: flex;
  229. flex-direction: column;
  230. align-items: center;
  231. padding: 1rem;
  232. margin: 1.5rem;
  233. }
  234. blockquote cite {
  235. font-style: italic;
  236. }
  237. blockquote p {
  238. margin-left: 0;
  239. }
  240. figure {
  241. border-top: .2vh solid #2d7474;
  242. background-color: #e3e1e1;
  243. text-align: center;
  244. padding: 1.5rem 0;
  245. margin: 1rem 0 0;
  246. font-size: 1.5rem;
  247. width: 100%;
  248. }
  249. figure img {
  250. max-width: 250px;
  251. max-height: 250px;
  252. border: .5vw solid #323a45;
  253. padding: 1px;
  254. }
  255. figcaption {
  256. padding: 1rem;
  257. line-height: 1.4;
  258. }
  259. aside {
  260. display: flex;
  261. flex-direction: column;
  262. background-color: #e3e1e1;
  263. padding: 1rem 0;
  264. border-bottom: .2vh solid #07486c;
  265. }
  266. aside p {
  267. max-width: 50rem;
  268. margin: 0 auto;
  269. }
  270. /* https://fvsch.com/code/css-locks/ */
  271. p, li, pre, code, kbd, samp, var, tt, time, details, figcaption {
  272. font-size: 1rem;
  273. line-height: calc( 1.5em + 0.2 * 1rem );
  274. }
  275. h1 {
  276. font-size: 1.9rem;
  277. line-height: calc( 1.2em + 0.2 * 1rem );
  278. }
  279. h2 {
  280. font-size: 1.6rem;
  281. line-height: calc( 1.3em + 0.2 * 1rem );
  282. }
  283. h3 {
  284. font-size: 1.35rem;
  285. line-height: calc( 1.4em + 0.2 * 1rem );
  286. }
  287. @media (min-width: 20em) {
  288. /* The (100vw - 20rem) / (50 - 20) part
  289. resolves to 0-1rem, depending on the
  290. viewport width (between 20em and 50em). */
  291. p, li, pre, code, kbd, samp, var, tt, time, details, figcaption {
  292. font-size: calc( 1rem + .6 * (100vw - 20rem) / (50 - 20) );
  293. line-height: calc( 1.5em + 0.2 * (100vw - 50rem) / (20 - 50) );
  294. margin-left: 0;
  295. }
  296. h1 {
  297. font-size: calc( 1.9rem + 1.5 * (100vw - 20rem) / (50 - 20) );
  298. line-height: calc( 1.2em + 0.2 * (100vw - 50rem) / (20 - 50) );
  299. }
  300. h2 {
  301. font-size: calc( 1.5rem + 1.5 * (100vw - 20rem) / (50 - 20) );
  302. line-height: calc( 1.3em + 0.2 * (100vw - 50rem) / (20 - 50) );
  303. }
  304. h3 {
  305. font-size: calc( 1.35rem + 1.5 * (100vw - 20rem) / (50 - 20) );
  306. line-height: calc( 1.4em + 0.2 * (100vw - 50rem) / (20 - 50) );
  307. }
  308. }
  309. @media (min-width: 50em) {
  310. /* The right part of the addition *must* be a
  311. rem value. In this example we *could* change
  312. the whole declaration to font-size:2.5rem,
  313. but if our baseline value was not expressed
  314. in rem we would have to use calc. */
  315. p, li, pre, code, kbd, samp, var, tt, time, details, figcaption {
  316. font-size: calc( 1rem + .6 * 1rem );
  317. line-height: 1.5em;
  318. }
  319. p, li, pre, details {
  320. margin-left: 3rem;
  321. }
  322. h1 {
  323. font-size: calc( 1.9rem + 1.5 * 1rem );
  324. line-height: 1.2em;
  325. }
  326. h2 {
  327. font-size: calc( 1.5rem + 1.5 * 1rem );
  328. line-height: 1.3em;
  329. }
  330. h3 {
  331. font-size: calc( 1.35rem + 1.5 * 1rem );
  332. line-height: 1.4em;
  333. }
  334. figure img {
  335. max-width: 500px;
  336. max-height: 500px;
  337. }
  338. }
  339. figure.unsquared {
  340. margin-bottom: 1.5rem;
  341. }
  342. figure.unsquared img {
  343. height: inherit;
  344. }
  345. @media print {
  346. body { font-size: 100%; }
  347. a:after { content: " (" attr(href) ")"; }
  348. a, a:link, a:visited, a:after {
  349. text-decoration: underline;
  350. text-shadow: none !important;
  351. background-image: none !important;
  352. background: white;
  353. color: black;
  354. }
  355. abbr[title] { border-bottom: 0; }
  356. abbr[title]:after { content: " (" attr(title) ")"; }
  357. img { page-break-inside: avoid; }
  358. @page { margin: 2cm .5cm; }
  359. h1, h2, h3 { page-break-after: avoid; }
  360. p3 { orphans: 3; widows: 3; }
  361. img {
  362. max-width: 250px !important;
  363. max-height: 250px !important;
  364. }
  365. nav, aside { display: none; }
  366. }
  367. ul.with_columns {
  368. column-count: 1;
  369. }
  370. @media (min-width: 20em) {
  371. ul.with_columns {
  372. column-count: 2;
  373. }
  374. }
  375. @media (min-width: 50em) {
  376. ul.with_columns {
  377. column-count: 3;
  378. }
  379. }
  380. ul.with_two_columns {
  381. column-count: 1;
  382. }
  383. @media (min-width: 20em) {
  384. ul.with_two_columns {
  385. column-count: 1;
  386. }
  387. }
  388. @media (min-width: 50em) {
  389. ul.with_two_columns {
  390. column-count: 2;
  391. }
  392. }
  393. .gallery {
  394. display: flex;
  395. flex-wrap: wrap;
  396. justify-content: space-around;
  397. }
  398. .gallery figure img {
  399. margin-left: 1rem;
  400. margin-right: 1rem;
  401. }
  402. .gallery figure figcaption {
  403. font-family: 'ConcourseT3'
  404. }
  405. footer {
  406. font-family: 'ConcourseT3';
  407. display: flex;
  408. flex-direction: column;
  409. border-top: 3px solid white;
  410. padding: 4rem 0;
  411. background-color: #07486c;
  412. color: white;
  413. }
  414. footer > * {
  415. max-width: 50rem;
  416. margin: 0 auto;
  417. }
  418. footer a {
  419. color: #f1c40f;
  420. }
  421. footer .avatar {
  422. width: 200px;
  423. height: 200px;
  424. border-radius: 50%;
  425. float: left;
  426. -webkit-shape-outside: circle();
  427. shape-outside: circle();
  428. margin-right: 2rem;
  429. padding: 2px 5px 5px 2px;
  430. background: white;
  431. border-left: 1px solid #f1c40f;
  432. border-top: 1px solid #f1c40f;
  433. border-right: 5px solid #f1c40f;
  434. border-bottom: 5px solid #f1c40f;
  435. }
  436. </style>
  437. <h1>
  438. <span><a id="jumper" href="#jumpto" title="Un peu perdu ?">?</a></span>
  439. Sass Guidelines (archive)
  440. <time>Pour la pérennité des contenus liés. Non-indexé, retrait sur simple email.</time>
  441. </h1>
  442. <section>
  443. <article>
  444. <h3><a href="http://sass-guidelin.es/">Source originale du contenu</a></h3>
  445. <h2 class="baseline">An opinionated styleguide for writing sane, maintainable and scalable Sass.</h2>
  446. <div class="translation-warning">
  447. <p>The Sass Guidelines project has been translated into several languages by <a target="_blank" href="https://github.com/HugoGiraudel/sass-guidelines/blob/gh-pages/_data/languages.yml">generous contributors</a>. Open the <button data-toggle="aside" class="link-like" role="button" type="button">options panel</button> to switch.</p>
  448. </div>
  449. <h1 id="about-the-author">About the author</h1>
  450. <p>My name is <a href="http://hugogiraudel.com">Hugo Giraudel</a>, I am a French front-end developer based in Berlin, Germany. I have been writing Sass for over two years now and am the author of Sass-related projects such as <a href="http://sassdoc.com">SassDoc</a> and <a href="http://sass-compatibility.github.io">Sass-Compatibility</a>. I also wrote a book about CSS (in French) entitled <a href="http://www.amazon.fr/dp/2212140231">CSS3 Pratique du Design Web</a>.</p>
  451. <p>I have also written a couple of Sass libraries, mostly for the heck of it: <a href="https://github.com/HugoGiraudel/SassyJSON">SassyJSON</a>, <a href="http://sassylists.com">SassyLists</a>, <a href="https://github.com/HugoGiraudel/SassySort">SassySort</a>, <a href="https://github.com/HugoGiraudel/SassyCast">SassyCast</a>, <a href="https://github.com/HugoGiraudel/SassyMatrix">SassyMatrix</a>, <a href="https://github.com/HugoGiraudel/SassyBitwise">SassyBitwise</a>, <a href="https://github.com/HugoGiraudel/SassyIteratorsGenerators">SassyIteratorsGenerators</a>, <a href="https://github.com/HugoGiraudel/SassyLogger">SassyLogger</a>, <a href="https://github.com/HugoGiraudel/SassyStrings">SassyStrings</a> and <a href="https://github.com/HugoGiraudel/SassyGradients">SassyGradients</a>.</p>
  452. <h1 id="contributing">Contributing</h1>
  453. <p>Sass Guidelines is a free project that I maintain in my spare time. Needless to say, it is quite a large amount of work to keep everything up-to-date, documented and relevant. Obviously, knowing that you liked this styleguide is already much appreciated!</p>
  454. <p>Now if you feel like contributing, please know that tweeting about it, spreading the word, or fixing a tiny typo by opening an issue or a pull-request on the <a href="https://github.com/HugoGiraudel/sass-guidelines">GitHub repository</a> would be great!</p>
  455. <p>Last but not least before we start: if you enjoyed this document, or if it is useful for you or your team, please consider supporting it!</p>
  456. <h1 id="table-of-contents">Table of Contents</h1>
  457. <h1 id="about-sass">About Sass</h1>
  458. <p>This is how <a href="http://sass-lang.com">Sass</a> describes itself in its <a href="http://sass-lang.com/documentation/file.SASS_REFERENCE.html">documentation</a>:</p>
  459. <blockquote>
  460. <p>Sass is an extension of CSS that adds power and elegance to the basic language.</p>
  461. </blockquote>
  462. <p>Sass’s ultimate objective is to fix CSS’s flaws. CSS, as we all know, is not the best language in the world <sup>[citation needed]</sup>. While very simple to learn, it can quickly get quite messy, especially on large projects.</p>
  463. <p>This is where Sass comes in, as a meta-language, to improve CSS’s syntax in order to provide extra features and handy tools. Meanwhile, Sass wants to be conservative regarding the CSS language.</p>
  464. <p>The point is not to turn CSS into a fully-featured programming language; Sass only wants to help where CSS fails. Because of this, getting started with Sass is no harder than learning CSS: it simply adds a couple of extra features on top of it.</p>
  465. <p>That being said, there are many ways to use these features. Some good, some bad, some unusual. These guidelines are meant to give you a consistent and documented approach to writing Sass code.</p>
  466. <h6 id="further-reading">Further reading</h6>
  467. <h2 id="ruby-sass-or-libsass">Ruby Sass or LibSass</h2>
  468. <p><a href="https://github.com/hcatlin/sass/commit/fa5048ba405619273e474a50400c7243fbff54fe">Sass’s first commit</a> goes back as far as late 2006, over 8 years ago. Needless to say it has come a long way since then. Initially developed in Ruby, varied ports popped up here and there. The most successful one, <a href="https://github.com/sass/libsass">LibSass</a> (written in C) is now close to being fully compatible with the original Ruby version.</p>
  469. <p>In 2014, <a href="https://github.com/sass/libsass/wiki/The-LibSass-Compatibility-Plan">Ruby Sass and LibSass teams decided to wait for both versions to sync up before moving forward</a>. Since then, LibSass has been actively releasing versions to have feature-parity with its older brother. The last remaining inconsistencies are gathered and listed by myself under the <a href="http://sass-compatibility.github.io">Sass-Compatibility</a> project. If you are aware of an incompatibility between the two versions that is not listed, please be kind enough to open an issue.</p>
  470. <p>Coming back to choosing your compiler. Actually, it all depends on your project. If it is a Ruby on Rails project, you better use Ruby Sass, which is perfectly suited for such a case. Also, be aware that Ruby Sass will always be the reference implementation and will always lead LibSass in features.</p>
  471. <p>On non-Ruby projects that need a workflow integration, LibSass is probably a better idea since it is mostly dedicated to being wrapped. So if you want to use, let’s say Node.js, <a href="https://github.com/sass/node-sass">node-sass</a> is all chosen.</p>
  472. <h6 id="further-reading-1">Further reading</h6>
  473. <h2 id="sass-or-scss">Sass or SCSS</h2>
  474. <p>There is quite a lot of confusion regarding the semantics of the name <em>Sass</em>, and for good reason: Sass means both the preprocessor and its own syntax. Not very convenient, is it?</p>
  475. <p>You see, Sass initially described a syntax of which the defining characteristic was its indentation-sensitivity. Soon enough, Sass maintainers decided to close the gap between Sass and CSS by providing a CSS-friendly syntax called <em>SCSS</em> for <em>Sassy CSS</em>. The motto is: if it’s valid CSS, it’s valid SCSS.</p>
  476. <p>Since then, Sass (the preprocessor) has been providing two different syntaxes: Sass (not all-caps, <a href="http://sassnotsass.com">please</a>), also known as <em>the indented syntax</em>, and SCSS. Which one to use is pretty much up to you since both are strictly equivalent in features. It’s only a matter of aesthetics at this point.</p>
  477. <p>Sass’s whitespace-sensitive syntax relies on indentation to get rid of braces, semi-colons and other punctuation symbols, leading to a leaner and shorter syntax. Meanwhile, SCSS is easier to learn since it’s mostly some tiny extra bits on top of CSS.</p>
  478. <p>I, myself, prefer SCSS over Sass because it is closer to CSS and friendlier to most developers. Because of that, SCSS is the default syntax throughout these guidelines. You can switch to Sass indented syntax in the <button data-toggle="aside" class="link-like" role="button" type="button">options panel</button>.</p>
  479. <h6 id="further-reading-2">Further reading</h6>
  480. <h2 id="other-preprocessors">Other preprocessors</h2>
  481. <p>Sass is a preprocessor among others. Its most serious competitor has to be <a href="http://lesscss.org/">LESS</a>, a Node.js based preprocessor that has gotten quite popular thanks to the famous CSS framework <a href="http://getbootstrap.com/">Bootstrap</a> using it. There is also <a href="http://learnboost.github.io/stylus/">Stylus</a> - which is kind of the nerdy, unrestricted version of LESS - where you can do pretty much whatever you want since it almost turns CSS into a programming language.</p>
  482. <p><em>Why choose Sass over LESS or another preprocessor?</em> is still a valid question today. Not so long ago, we used to recommend Sass for Ruby-based projects because it was first made in Ruby and played well with Ruby on Rails. Now that LibSass has caught up (mostly) with original Sass, this is no longer relevant advice.</p>
  483. <p>What I do like with Sass is its conservative approach to CSS. Sass’s design is based on strong principles: much of the design approach comes naturally out of the core teams’ beliefs that a) adding extra features has a complexity cost that needs to be justified by usefulness and, b) it should be easy to reason about what a given block of styles is doing by looking at that block alone. Also, Sass has a much sharper attention to detail than other preprocessors. As far as I can tell, the core designers care deeply about supporting every corner-case of CSS compatibility and making sure every general behavior is consistent.</p>
  484. <p>In other words, Sass is not a preprocessor aimed at pleasing nerdy wannabe programmers like me by adding extraordinary features on top of a language that is not intended to support any logical use-cases. It is a software aimed at solving actual issues; helping to provide useful functionality to CSS where CSS falls short.</p>
  485. <p>Preprocessors aside, we should also mention postprocessors, which have received significant exposure in the last few months, thanks mainly to <a href="https://github.com/postcss/postcss">PostCSS</a> and <a href="https://cssnext.github.io/">cssnext</a>. Postprocessors are pretty much equivalent to preprocessors except they do not provide anything else other than upcoming CSS syntax.</p>
  486. <p>You can think of postprocessors as a polyfill for unsupported CSS features. For instance, you would write variables as they are described in the <a href="http://dev.w3.org/csswg/css-variables/">CSS specifications</a>, then compile your stylesheets with a postprocessor only to find every variable occurrence gets replaced with its value, as Sass would do.</p>
  487. <p>The idea behind postprocessors is that once browsers support new features (e.g. CSS variables), the postprocessor does not compile them anymore and lets browsers take over.</p>
  488. <p>While providing tomorrow’s syntax today is something of a noble idea, I have to say I still prefer using Sass for most tasks. However, there are some occasions where I believe postprocessors are more suited than Sass and the like - CSS prefixing for instance - but we’ll get back to this.</p>
  489. <h6 id="further-reading-3">Further reading</h6>
  490. <h1 id="introduction">Introduction</h1>
  491. <h2 id="why-a-styleguide">Why a styleguide</h2>
  492. <p>A styleguide is not just a pleasing document to read, picturing an ideal state for your code. It is a key document in a project’s life, describing how and why code should be written. It may look like overkill for small projects, but it helps a lot in keeping the codebase clean, scalable and easily maintainable.</p>
  493. <p>Needless to say, the more developers involved on a project, the more code guidelines are needed. Along the same lines, the bigger the project, the more a styleguide is a must.</p>
  494. <p><a href="http://csswizardry.com">Harry Roberts</a> states it very well in <a href="http://cssguidelin.es/#the-importance-of-a-styleguide">CSS Guidelines</a>:</p>
  495. <blockquote>
  496. <p>A coding styleguide (note, not a visual styleguide) is a valuable tool for teams who:</p>
  497. <ul>
  498. <li>build and maintain products for a reasonable length of time;</li>
  499. <li>have developers of differing abilities and specialties;</li>
  500. <li>have a number of different developers working on a product at any given time;</li>
  501. <li>on-board new staff regularly;</li>
  502. <li>have a number of codebases that developers dip in and out of.</li>
  503. </ul>
  504. </blockquote>
  505. <h2 id="disclaimer">Disclaimer</h2>
  506. <p>First things first: <strong>this is not a CSS styleguide</strong>. This document will not discuss naming conventions for CSS classes, modular patterns and the question of IDs in the CSS world. These guidelines only aim at dealing with Sass-specific content.</p>
  507. <p>Also, this styleguide is my own and therefore <strong>very opinionated</strong>. Think of it as a collection of methodologies and advice that I have polished and given over the years. It also gives me the opportunity to link to a handful of insightful resources, so be sure to check the <em>further readings</em>.</p>
  508. <p>Obviously, this is certainly not the only way of doing things, and it may or may not suit your project. Feel free to pick from it and adapt it to your needs. As we say, <em>your mileage may vary</em>.</p>
  509. <h2 id="key-principles">Key principles</h2>
  510. <p>At the end of the day, if there is one thing I would like you to get from this whole styleguide, it is that <strong>Sass should be kept as simple as it can be</strong>.</p>
  511. <p>Thanks to my silly experiments like <a href="https://github.com/HugoGiraudel/SassyBitwise">bitwise operators</a>, <a href="https://github.com/HugoGiraudel/SassyIteratorsGenerators">iterators and generators</a> and <a href="https://github.com/HugoGiraudel/SassyJSON">a JSON parser</a> in Sass, we are all well aware of what one can do with this preprocessor.</p>
  512. <p>Meanwhile, CSS is a simple language. Sass, being intended to write CSS, should not get much more complex than regular CSS. The <a href="http://en.wikipedia.org/wiki/KISS_principle">KISS principle</a> (Keep It Simple Stupid) is key here and may even take precedence over the <a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY principle</a> (Don’t Repeat Yourself) in some circumstances.</p>
  513. <p>Sometimes, it’s better to repeat a little to keep the code maintainable, rather than building a top-heavy, unwieldy, unnecessarily complicated system that is completely unmaintainable because it is overly complex.</p>
  514. <p>Also, and let me quote <a href="https://csswizardry.com">Harry Roberts</a> once again, <strong>pragmatism trumps perfection</strong>. At some point, you will probably find yourself going against the rules described here. If it makes sense, if it feels right, do it. Code is just a means, not an end.</p>
  515. <h6 id="further-reading-4">Further reading</h6>
  516. <h1 id="syntax--formatting">Syntax &amp; formatting</h1>
  517. <p>If you ask me, the very first thing a styleguide should do is describe the way we want our code to look.</p>
  518. <p>When several developers are involved in writing CSS on the same project(s), it is only a matter of time before one of them starts doing things their own way. Code guidelines that promote consistency not only prevent this, but also help when it comes to reading and updating the code.</p>
  519. <p>Roughly, we want (shamelessly inspired by <a href="http://cssguidelin.es/#syntax-and-formatting">CSS Guidelines</a>):</p>
  520. <ul>
  521. <li>two (2) spaces indents, no tabs;</li>
  522. <li>ideally, 80-characters wide lines;</li>
  523. <li>properly written multi-line CSS rules;</li>
  524. <li>meaningful use of whitespace.</li>
  525. </ul>
  526. <div class="code-block">
  527. <div class="code-block__wrapper" data-syntax="scss">
  528. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Yep</span>
  529. <span class="nc">.foo</span> <span class="p">{</span>
  530. <span class="na">display</span><span class="o">:</span> <span class="no">block</span><span class="p">;</span>
  531. <span class="na">overflow</span><span class="o">:</span> <span class="no">hidden</span><span class="p">;</span>
  532. <span class="na">padding</span><span class="o">:</span> <span class="mi">0</span> <span class="mi">1</span><span class="kt">em</span><span class="p">;</span>
  533. <span class="p">}</span>
  534. <span class="c1">// Nope</span>
  535. <span class="nc">.foo</span> <span class="p">{</span>
  536. <span class="na">display</span><span class="o">:</span> <span class="no">block</span><span class="p">;</span> <span class="na">overflow</span><span class="o">:</span> <span class="no">hidden</span><span class="p">;</span>
  537. <span class="na">padding</span><span class="o">:</span> <span class="mi">0</span> <span class="mi">1</span><span class="kt">em</span><span class="p">;</span>
  538. <span class="p">}</span></code></pre></div>
  539. </div>
  540. <div class="code-block__wrapper" data-syntax="sass">
  541. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Since Sass indented-syntax forces those coding standards</span>
  542. <span class="c1">// There is no wrong way of proceeding</span>
  543. <span class="nc">.foo</span>
  544. <span class="na">display</span><span class="o">:</span> <span class="no">block</span>
  545. <span class="na">overflow</span><span class="o">:</span> <span class="no">hidden</span>
  546. <span class="na">padding</span><span class="o">:</span> <span class="mi">0</span> <span class="mi">1</span><span class="kt">em</span></code></pre></div>
  547. </div>
  548. </div>
  549. <p>We will not tackle the question of file organization in this section. It is the object of <a href="#architecture">another section</a>.</p>
  550. <h2 id="strings">Strings</h2>
  551. <p>Believe it or not, strings play quite a large role in both CSS and Sass ecosystems. Most CSS values are either lengths or strings (usually unquoted), so it actually is quite crucial to stick to some guidelines when dealing with strings in Sass.</p>
  552. <h3 id="encoding">Encoding</h3>
  553. <p>To avoid any potential issue with character encoding, it is highly recommended to force <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a> encoding in the <a href="#main-file">main stylesheet</a> using the <code>@charset</code> directive. Make sure it is the very first element of the stylesheet and there is no character of any kind before it.</p>
  554. <h3 id="quotes">Quotes</h3>
  555. <p>CSS does not require strings to be quoted, not even those containing spaces. Take font-family names for instance: it doesn’t matter whether you wrap them in quotes for the CSS parser.</p>
  556. <p>Because of this, Sass <em>also</em> does not require strings to be quoted. Even better (and <em>luckily</em>, you’ll concede), a quoted string is strictly equivalent to its unquoted twin (e.g. <code>'abc'</code> is strictly equal to <code>abc</code>).</p>
  557. <p>That being said, languages that do not require strings to be quoted are definitely a minority and so, <strong>strings should always be wrapped with single quotes</strong> (<code>'</code>) in Sass (single being easier to type than double on <em>qwerty</em> keyboards). Besides consistency with other languages, including CSS’ cousin JavaScript, there are several reasons for this choice:</p>
  558. <ul>
  559. <li>color names are treated as colors when unquoted, which can lead to serious issues;</li>
  560. <li>most syntax highlighters will choke on unquoted strings;</li>
  561. <li>it helps general readability;</li>
  562. <li>there is no valid reason not to quote strings.</li>
  563. </ul>
  564. <div class="code-block">
  565. <div class="code-block__wrapper" data-syntax="scss">
  566. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Yep</span>
  567. <span class="nv">$direction</span><span class="o">:</span> <span class="s1">'</span><span class="s2">left'</span><span class="p">;</span>
  568. <span class="c1">// Nope</span>
  569. <span class="nv">$direction</span><span class="o">:</span> <span class="no">left</span><span class="p">;</span></code></pre></div>
  570. </div>
  571. <div class="code-block__wrapper" data-syntax="sass">
  572. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Yep</span>
  573. <span class="nv">$direction</span><span class="o">:</span> <span class="s1">'</span><span class="s2">left'</span>
  574. <span class="c1">// Nope</span>
  575. <span class="nv">$direction</span><span class="o">:</span> <span class="no">left</span></code></pre></div>
  576. </div>
  577. </div>
  578. <h3 id="strings-as-css-values">Strings as CSS values</h3>
  579. <p>Specific CSS values such as <code>initial</code> or <code>sans-serif</code> require not to be quoted. Indeed, the declaration <code>font-family: 'sans-serif'</code> will silently fail because CSS is expecting an identifier, not a quoted string. Because of this, we do not quote those values.</p>
  580. <div class="code-block">
  581. <div class="code-block__wrapper" data-syntax="scss">
  582. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Yep</span>
  583. <span class="nv">$font-type</span><span class="o">:</span> <span class="no">sans-serif</span><span class="p">;</span>
  584. <span class="c1">// Nope</span>
  585. <span class="nv">$font-type</span><span class="o">:</span> <span class="s1">'</span><span class="s2">sans-serif'</span><span class="p">;</span>
  586. <span class="c1">// Okay I guess</span>
  587. <span class="nv">$font-type</span><span class="o">:</span> <span class="nf">unquote</span><span class="p">(</span><span class="s1">'</span><span class="s2">sans-serif'</span><span class="p">);</span></code></pre></div>
  588. </div>
  589. <div class="code-block__wrapper" data-syntax="sass">
  590. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Yep</span>
  591. <span class="na">$font-type</span><span class="o">:</span> <span class="no">sans-serif</span>
  592. <span class="c1">// Nope</span>
  593. <span class="na">$font-type</span><span class="o">:</span> <span class="s1">'</span><span class="s2">sans-serif'</span>
  594. <span class="c1">// Okay I guess</span>
  595. <span class="na">$font-type</span><span class="o">:</span> <span class="nf">unquote</span><span class="p">(</span><span class="s1">'</span><span class="s2">sans-serif'</span><span class="p">)</span></code></pre></div>
  596. </div>
  597. </div>
  598. <p>Hence, we can make a distinction between strings intended to be used as CSS values (CSS identifiers) like in the previous example, and strings when sticking to the Sass data type, for instance map keys.</p>
  599. <p>We don’t quote the former, but we do wrap the latter in single quotes.</p>
  600. <h3 id="strings-containing-quotes">Strings containing quotes</h3>
  601. <p>If a string contains one or several single quotes, one might consider wrapping the string with double quotes (<code>"</code>) instead, in order to avoid escaping too many characters within the string.</p>
  602. <div class="code-block">
  603. <div class="code-block__wrapper" data-syntax="scss">
  604. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Okay</span>
  605. <span class="k">@warn</span> <span class="s1">'</span><span class="s2">You can\'t do that.'</span><span class="p">;</span>
  606. <span class="c1">// Okay</span>
  607. <span class="k">@warn</span> <span class="s2">"You can't do that."</span><span class="p">;</span></code></pre></div>
  608. </div>
  609. <div class="code-block__wrapper" data-syntax="sass">
  610. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Okay</span>
  611. <span class="k">@warn</span> <span class="s1">'</span><span class="s2">You can\'t do that.'</span>
  612. <span class="c1">// Okay</span>
  613. <span class="k">@warn</span> <span class="s2">"You can't do that."</span></code></pre></div>
  614. </div>
  615. </div>
  616. <h3 id="urls">URLs</h3>
  617. <p>URLs should be quoted as well, for the same reasons as above:</p>
  618. <div class="code-block">
  619. <div class="code-block__wrapper" data-syntax="scss">
  620. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Yep</span>
  621. <span class="nc">.foo</span> <span class="p">{</span>
  622. <span class="na">background-image</span><span class="o">:</span> <span class="sx">url('/images/kittens.jpg')</span><span class="p">;</span>
  623. <span class="p">}</span>
  624. <span class="c1">// Nope</span>
  625. <span class="nc">.foo</span> <span class="p">{</span>
  626. <span class="na">background-image</span><span class="o">:</span> <span class="sx">url(/images/kittens.jpg)</span><span class="p">;</span>
  627. <span class="p">}</span></code></pre></div>
  628. </div>
  629. <div class="code-block__wrapper" data-syntax="sass">
  630. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Yep</span>
  631. <span class="nc">.foo</span>
  632. <span class="na">background-image</span><span class="o">:</span> <span class="sx">url('/images/kittens.jpg')</span>
  633. <span class="c1">// Nope</span>
  634. <span class="nc">.foo</span>
  635. <span class="na">background-image</span><span class="o">:</span> <span class="sx">url(/images/kittens.jpg)</span></code></pre></div>
  636. </div>
  637. </div>
  638. <h6 id="further-reading-5">Further reading</h6>
  639. <h2 id="numbers">Numbers</h2>
  640. <p>In Sass, number is a data type including everything from unitless numbers to lengths, durations, frequencies, angles and so on. This allows calculations to be run on such measures.</p>
  641. <h3 id="zeros">Zeros</h3>
  642. <p>Numbers should display leading zeros before a decimal value less than one. Never display trailing zeros.</p>
  643. <div class="code-block">
  644. <div class="code-block__wrapper" data-syntax="scss">
  645. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Yep</span>
  646. <span class="nc">.foo</span> <span class="p">{</span>
  647. <span class="na">padding</span><span class="o">:</span> <span class="mi">2</span><span class="kt">em</span><span class="p">;</span>
  648. <span class="na">opacity</span><span class="o">:</span> <span class="mi">0</span><span class="mf">.5</span><span class="p">;</span>
  649. <span class="p">}</span>
  650. <span class="c1">// Nope</span>
  651. <span class="nc">.foo</span> <span class="p">{</span>
  652. <span class="na">padding</span><span class="o">:</span> <span class="mi">2</span><span class="mf">.0</span><span class="kt">em</span><span class="p">;</span>
  653. <span class="na">opacity</span><span class="o">:</span> <span class="mf">.5</span><span class="p">;</span>
  654. <span class="p">}</span></code></pre></div>
  655. </div>
  656. <div class="code-block__wrapper" data-syntax="sass">
  657. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Yep</span>
  658. <span class="nc">.foo</span>
  659. <span class="na">padding</span><span class="o">:</span> <span class="mi">2</span><span class="kt">em</span>
  660. <span class="na">opacity</span><span class="o">:</span> <span class="mi">0</span><span class="mf">.5</span>
  661. <span class="c1">// Nope</span>
  662. <span class="nc">.foo</span>
  663. <span class="na">padding</span><span class="o">:</span> <span class="mi">2</span><span class="mf">.0</span><span class="kt">em</span>
  664. <span class="na">opacity</span><span class="o">:</span> <span class="mf">.5</span></code></pre></div>
  665. </div>
  666. </div>
  667. <h3 id="units">Units</h3>
  668. <p>When dealing with lengths, a <code>0</code> value should never ever have a unit.</p>
  669. <div class="code-block">
  670. <div class="code-block__wrapper" data-syntax="scss">
  671. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Yep</span>
  672. <span class="nv">$length</span><span class="o">:</span> <span class="mi">0</span><span class="p">;</span>
  673. <span class="c1">// Nope</span>
  674. <span class="nv">$length</span><span class="o">:</span> <span class="mi">0</span><span class="kt">em</span><span class="p">;</span></code></pre></div>
  675. </div>
  676. <div class="code-block__wrapper" data-syntax="sass">
  677. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Yep</span>
  678. <span class="nv">$length</span><span class="o">:</span> <span class="mi">0</span>
  679. <span class="c1">// Nope</span>
  680. <span class="nv">$length</span><span class="o">:</span> <span class="mi">0</span><span class="kt">em</span></code></pre></div>
  681. </div>
  682. </div>
  683. <p>The most common mistake I can think of regarding numbers in Sass, is thinking that units are just some strings that can be safely appended to a number. While that sounds true, it is certainly not how units work. Think of units as algebraic symbols. For instance, in the real world, multiplying 5 inches by 5 inches gives you 25 square inches. The same logic applies to Sass.</p>
  684. <p>To add a unit to a number, you have to multiply this number by <em>1 unit</em>.</p>
  685. <div class="code-block">
  686. <div class="code-block__wrapper" data-syntax="scss">
  687. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="nv">$value</span><span class="o">:</span> <span class="mi">42</span><span class="p">;</span>
  688. <span class="c1">// Yep</span>
  689. <span class="nv">$length</span><span class="o">:</span> <span class="nv">$value</span> <span class="o">*</span> <span class="mi">1</span><span class="kt">px</span><span class="p">;</span>
  690. <span class="c1">// Nope</span>
  691. <span class="nv">$length</span><span class="o">:</span> <span class="nv">$value</span> <span class="o">+</span> <span class="no">px</span><span class="p">;</span></code></pre></div>
  692. </div>
  693. <div class="code-block__wrapper" data-syntax="sass">
  694. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="nv">$value</span><span class="o">:</span> <span class="mi">42</span>
  695. <span class="c1">// Yep</span>
  696. <span class="nv">$length</span><span class="o">:</span> <span class="nv">$value</span> <span class="o">*</span> <span class="mi">1</span><span class="kt">px</span>
  697. <span class="c1">// Nope</span>
  698. <span class="nv">$length</span><span class="o">:</span> <span class="nv">$value</span> <span class="o">+</span> <span class="no">px</span></code></pre></div>
  699. </div>
  700. </div>
  701. <p>Note that adding <em>0 member of that unit</em> also works, but I would rather recommend the aforementioned method since adding <em>0 unit</em> can be a bit confusing. Indeed, when trying to convert a number to another compatible unit, adding 0 will not do the trick.</p>
  702. <div class="code-block">
  703. <div class="code-block__wrapper" data-syntax="scss">
  704. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="nv">$value</span><span class="o">:</span> <span class="mi">42</span> <span class="o">+</span> <span class="mi">0</span><span class="kt">px</span><span class="p">;</span>
  705. <span class="c1">// -&gt; 42px</span>
  706. <span class="nv">$value</span><span class="o">:</span> <span class="mi">1</span><span class="kt">in</span> <span class="o">+</span> <span class="mi">0</span><span class="kt">px</span><span class="p">;</span>
  707. <span class="c1">// -&gt; 1in</span>
  708. <span class="nv">$value</span><span class="o">:</span> <span class="mi">0</span><span class="kt">px</span> <span class="o">+</span> <span class="mi">1</span><span class="kt">in</span><span class="p">;</span>
  709. <span class="c1">// -&gt; 96px</span></code></pre></div>
  710. </div>
  711. <div class="code-block__wrapper" data-syntax="sass">
  712. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="nv">$value</span><span class="o">:</span> <span class="mi">42</span> <span class="o">+</span> <span class="mi">0</span><span class="kt">px</span>
  713. <span class="c1">// -&gt; 42px</span>
  714. <span class="nv">$value</span><span class="o">:</span> <span class="mi">1</span><span class="kt">in</span> <span class="o">+</span> <span class="mi">0</span><span class="kt">px</span>
  715. <span class="c1">// -&gt; 1in</span>
  716. <span class="nv">$value</span><span class="o">:</span> <span class="mi">0</span><span class="kt">px</span> <span class="o">+</span> <span class="mi">1</span><span class="kt">in</span>
  717. <span class="c1">// -&gt; 96px</span></code></pre></div>
  718. </div>
  719. </div>
  720. <p>In the end, it really depends on what you are trying to achieve. Just keep in mind that adding the unit as a string is not a good way to proceed.</p>
  721. <p>To remove the unit of a value, you have to divide it by <em>one unit of its kind</em>.</p>
  722. <div class="code-block">
  723. <div class="code-block__wrapper" data-syntax="scss">
  724. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="nv">$length</span><span class="o">:</span> <span class="mi">42</span><span class="kt">px</span><span class="p">;</span>
  725. <span class="c1">// Yep</span>
  726. <span class="nv">$value</span><span class="o">:</span> <span class="nv">$length</span> <span class="o">/</span> <span class="mi">1</span><span class="kt">px</span><span class="p">;</span>
  727. <span class="c1">// Nope</span>
  728. <span class="nv">$value</span><span class="o">:</span> <span class="nf">str-slice</span><span class="p">(</span><span class="nv">$length</span> <span class="o">+</span> <span class="nf">unquote</span><span class="p">(</span><span class="s1">'</span><span class="s2">'</span><span class="p">)</span><span class="o">,</span> <span class="mi">1</span><span class="o">,</span> <span class="mi">2</span><span class="p">);</span></code></pre></div>
  729. </div>
  730. <div class="code-block__wrapper" data-syntax="sass">
  731. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="nv">$length</span><span class="o">:</span> <span class="mi">42</span><span class="kt">px</span>
  732. <span class="c1">// Yep</span>
  733. <span class="nv">$value</span><span class="o">:</span> <span class="nv">$length</span> <span class="o">/</span> <span class="mi">1</span><span class="kt">px</span>
  734. <span class="c1">// Nope</span>
  735. <span class="nv">$value</span><span class="o">:</span> <span class="nf">str-slice</span><span class="p">(</span><span class="nv">$length</span> <span class="o">+</span> <span class="nf">unquote</span><span class="p">(</span><span class="s1">'</span><span class="s2">'</span><span class="p">)</span><span class="o">,</span> <span class="mi">1</span><span class="o">,</span> <span class="mi">2</span><span class="p">)</span></code></pre></div>
  736. </div>
  737. </div>
  738. <p>Appending a unit as a string to a number results in a string, preventing any additional operation on the value. Slicing the numeric part of a number with a unit also results in a string. This is not what you want.</p>
  739. <h3 id="calculations">Calculations</h3>
  740. <p><strong>Top-level numeric calculations should always be wrapped in parentheses</strong>. Not only does this requirement dramatically improve readability, it also prevents some edge cases by forcing Sass to evaluate the contents of the parentheses.</p>
  741. <div class="code-block">
  742. <div class="code-block__wrapper" data-syntax="scss">
  743. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Yep</span>
  744. <span class="nc">.foo</span> <span class="p">{</span>
  745. <span class="na">width</span><span class="o">:</span> <span class="p">(</span><span class="mi">100</span><span class="kt">%</span> <span class="o">/</span> <span class="mi">3</span><span class="p">);</span>
  746. <span class="p">}</span>
  747. <span class="c1">// Nope</span>
  748. <span class="nc">.foo</span> <span class="p">{</span>
  749. <span class="na">width</span><span class="o">:</span> <span class="mi">100</span><span class="kt">%</span> <span class="o">/</span> <span class="mi">3</span><span class="p">;</span>
  750. <span class="p">}</span></code></pre></div>
  751. </div>
  752. <div class="code-block__wrapper" data-syntax="sass">
  753. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Yep</span>
  754. <span class="nc">.foo</span>
  755. <span class="na">width</span><span class="o">:</span> <span class="p">(</span><span class="mi">100</span><span class="kt">%</span> <span class="o">/</span> <span class="mi">3</span><span class="p">)</span>
  756. <span class="c1">// Nope</span>
  757. <span class="nc">.foo</span>
  758. <span class="na">width</span><span class="o">:</span> <span class="mi">100</span><span class="kt">%</span> <span class="o">/</span> <span class="mi">3</span></code></pre></div>
  759. </div>
  760. </div>
  761. <h3 id="magic-numbers">Magic numbers</h3>
  762. <p>“Magic number” is an <a href="http://en.wikipedia.org/wiki/Magic_number_(programming)#Unnamed_numerical_constants">old school programming</a> term for <em>unnamed numerical constant</em>. Basically, it’s just a random number that happens to <em>just work</em>™ yet is not tied to any logical explanation.</p>
  763. <p>Needless to say <strong>magic numbers are a plague and should be avoided at all costs</strong>. When you cannot manage to find a reasonable explanation for why a number works, add an extensive comment explaining how you got there and why you think it works. Admitting you don’t know why something works is still more helpful to the next developer than them having to figure out what’s going on from scratch.</p>
  764. <div class="code-block">
  765. <div class="code-block__wrapper" data-syntax="scss">
  766. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="cm">/**</span>
  767. <span class="cm"> * 1. Magic number. This value is the lowest I could find to align the top of</span>
  768. <span class="cm"> * `.foo` with its parent. Ideally, we should fix it properly.</span>
  769. <span class="cm"> */</span>
  770. <span class="nc">.foo</span> <span class="p">{</span>
  771. <span class="na">top</span><span class="o">:</span> <span class="mi">0</span><span class="mf">.327</span><span class="kt">em</span><span class="p">;</span> <span class="cm">/* 1 */</span>
  772. <span class="p">}</span></code></pre></div>
  773. </div>
  774. <div class="code-block__wrapper" data-syntax="sass">
  775. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="cm">/**</span>
  776. <span class="cm">* 1. Magic number. This value is the lowest I could find to align the top of</span>
  777. <span class="cm">* `.foo` with its parent. Ideally, we should fix it properly.</span>
  778. <span class="cm">*/</span>
  779. <span class="nc">.foo</span>
  780. <span class="na">top</span><span class="o">:</span> <span class="mi">0</span><span class="mf">.327</span><span class="kt">em</span> <span class="cm">/* 1 </span><span class="c">*/</span></code></pre></div>
  781. </div>
  782. </div>
  783. <h6 id="further-reading-6">Further reading</h6>
  784. <h2 id="colors">Colors</h2>
  785. <p>Colors occupy an important place in the CSS language. Naturally, Sass ends up being a valuable ally when it comes to manipulating colors, mostly by providing a handful of <a href="http://sass-lang.com/documentation/Sass/Script/Functions.html">powerful functions</a>.</p>
  786. <h3 id="color-formats">Color formats</h3>
  787. <p>In order to make colors as simple as they can be, my advice would be to respect the following order of preference for color formats:</p>
  788. <ol>
  789. <li><a href="http://www.w3.org/TR/css3-color/#svg-color">CSS color keywords</a>;</li>
  790. <li><a href="http://en.wikipedia.org/wiki/HSL_and_HSV">HSL notation</a>;</li>
  791. <li><a href="http://en.wikipedia.org/wiki/RGB_color_model">RGB notation</a>;</li>
  792. <li>Hexadecimal notation. Preferably lowercase and shortened when possible.</li>
  793. </ol>
  794. <p>For starters, keywords often speak for themselves. The HSL representation is not only the easiest one for the human brain to comprehend<sup>[citation needed]</sup>, it also makes it easy for stylesheet authors to tweak the color by adjusting the hue, saturation and lightness individually. RGB still has the benefit of showing right away if the color is more of a blue, a green or a red but it does not make it easy to build a color from the three parts. Lastly, hexadecimal is close to indecipherable for the human mind.</p>
  795. <div class="code-block">
  796. <div class="code-block__wrapper" data-syntax="scss">
  797. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Yep</span>
  798. <span class="nc">.foo</span> <span class="p">{</span>
  799. <span class="na">color</span><span class="o">:</span> <span class="nb">red</span><span class="p">;</span>
  800. <span class="p">}</span>
  801. <span class="c1">// Nope</span>
  802. <span class="nc">.foo</span> <span class="p">{</span>
  803. <span class="na">color</span><span class="o">:</span> <span class="mh">#FF0000</span><span class="p">;</span>
  804. <span class="p">}</span></code></pre></div>
  805. </div>
  806. <div class="code-block__wrapper" data-syntax="sass">
  807. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Yep</span>
  808. <span class="nc">.foo</span>
  809. <span class="na">color</span><span class="o">:</span> <span class="nb">red</span>
  810. <span class="c1">// Nope</span>
  811. <span class="nc">.foo</span>
  812. <span class="na">color</span><span class="o">:</span> <span class="mh">#FF0000</span></code></pre></div>
  813. </div>
  814. </div>
  815. <p>When using HSL or RGB notation, always add a single space after a comma (<code>,</code>) and no space between parentheses (<code>(</code>, <code>)</code>) and content.</p>
  816. <div class="code-block">
  817. <div class="code-block__wrapper" data-syntax="scss">
  818. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Yep</span>
  819. <span class="nc">.foo</span> <span class="p">{</span>
  820. <span class="na">color</span><span class="o">:</span> <span class="nf">rgba</span><span class="p">(</span><span class="mi">0</span><span class="o">,</span> <span class="mi">0</span><span class="o">,</span> <span class="mi">0</span><span class="o">,</span> <span class="mi">0</span><span class="mf">.1</span><span class="p">);</span>
  821. <span class="na">background</span><span class="o">:</span> <span class="nf">hsl</span><span class="p">(</span><span class="mi">300</span><span class="o">,</span> <span class="mi">100</span><span class="kt">%</span><span class="o">,</span> <span class="mi">100</span><span class="kt">%</span><span class="p">);</span>
  822. <span class="p">}</span>
  823. <span class="c1">// Nope</span>
  824. <span class="nc">.foo</span> <span class="p">{</span>
  825. <span class="na">color</span><span class="o">:</span> <span class="nf">rgba</span><span class="p">(</span><span class="mi">0</span><span class="o">,</span><span class="mi">0</span><span class="o">,</span><span class="mi">0</span><span class="o">,</span><span class="mi">0</span><span class="mf">.1</span><span class="p">);</span>
  826. <span class="na">background</span><span class="o">:</span> <span class="nf">hsl</span><span class="p">(</span> <span class="mi">300</span><span class="o">,</span> <span class="mi">100</span><span class="kt">%</span><span class="o">,</span> <span class="mi">100</span><span class="kt">%</span> <span class="p">);</span>
  827. <span class="p">}</span></code></pre></div>
  828. </div>
  829. <div class="code-block__wrapper" data-syntax="sass">
  830. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Yep</span>
  831. <span class="nc">.foo</span>
  832. <span class="na">color</span><span class="o">:</span> <span class="nf">rgba</span><span class="p">(</span><span class="mi">0</span><span class="o">,</span> <span class="mi">0</span><span class="o">,</span> <span class="mi">0</span><span class="o">,</span> <span class="mi">0</span><span class="mf">.1</span><span class="p">)</span>
  833. <span class="na">background</span><span class="o">:</span> <span class="nf">hsl</span><span class="p">(</span><span class="mi">300</span><span class="o">,</span> <span class="mi">100</span><span class="kt">%</span><span class="o">,</span> <span class="mi">100</span><span class="kt">%</span><span class="p">)</span>
  834. <span class="c1">// Nope</span>
  835. <span class="nc">.foo</span>
  836. <span class="na">color</span><span class="o">:</span> <span class="nf">rgba</span><span class="p">(</span><span class="mi">0</span><span class="o">,</span><span class="mi">0</span><span class="o">,</span><span class="mi">0</span><span class="o">,</span><span class="mi">0</span><span class="mf">.1</span><span class="p">)</span>
  837. <span class="na">background</span><span class="o">:</span> <span class="nf">hsl</span><span class="p">(</span> <span class="mi">300</span><span class="o">,</span> <span class="mi">100</span><span class="kt">%</span><span class="o">,</span> <span class="mi">100</span><span class="kt">%</span> <span class="p">)</span></code></pre></div>
  838. </div>
  839. </div>
  840. <h3 id="colors-and-variables">Colors and variables</h3>
  841. <p>When using a color more than once, store it in a variable with a meaningful name representing the color.</p>
  842. <p>Now you are free to use this variable wherever you want. However, if your usage is strongly tied to a theme, I would advise against using the variable as is. Instead, store it in another variable with a name explaining how it should be used.</p>
  843. <div class="code-block">
  844. <div class="code-block__wrapper" data-syntax="scss">
  845. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="nv">$main-theme-color</span><span class="o">:</span> <span class="nv">$sass-pink</span><span class="p">;</span></code></pre></div>
  846. </div>
  847. <div class="code-block__wrapper" data-syntax="sass">
  848. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="na">$main-theme-color</span><span class="o">:</span> <span class="nv">$sass-pink</span></code></pre></div>
  849. </div>
  850. </div>
  851. <p>Doing this would prevent a theme change leading to something like <code>$sass-pink: blue</code>.</p>
  852. <h3 id="lightening-and-darkening-colors">Lightening and darkening colors</h3>
  853. <p>Both <a href="http://sass-lang.com/documentation/Sass/Script/Functions.html#lighten-instance_method"><code>lighten</code></a> and <a href="http://sass-lang.com/documentation/Sass/Script/Functions.html#darken-instance_method"><code>darken</code></a> functions manipulate the lightness of a color in the HSL space by adding to or subtracting from the lightness in the HSL space. Basically, they are nothing but aliases for the <code>$lightness</code> parameter of the <a href="http://sass-lang.com/documentation/Sass/Script/Functions.html#adjust_color-instance_method"><code>adjust-color</code></a> function.</p>
  854. <p>The thing is, those functions often do not provide the expected result. On the other hand, the <a href="http://sass-lang.com/documentation/Sass/Script/Functions.html#mix-instance_method"><code>mix</code></a> function is a nice way to lighten or darken a color by mixing it with either <code>white</code> or <code>black</code>.</p>
  855. <p>The benefit of using <code>mix</code> rather than one of the two aforementioned functions is that it will progressively go to black (or white) as you decrease the proportion of the color, whereas <code>darken</code> and <code>lighten</code> will quickly blow out a color all the way to black or white.</p>
  856. <figure role="group">
  857. <img alt="Illustration of the difference between lighten/darken and mix by KatieK&#10;" sizes="100vw" srcset="http://sass-guidelin.es/assets/images/lighten-darken-mix_small.png 540w,&#10; http://sass-guidelin.es/assets/images/lighten-darken-mix_medium.png 900w,&#10; http://sass-guidelin.es/assets/images/lighten-darken-mix_large.png 1200w,&#10; http://sass-guidelin.es/assets/images/lighten-darken-mix_huge.png 1590w"/>
  858. <figcaption><p>Illustration of the difference between <code>lighten</code>/<code>darken</code> and <code>mix</code> by <a href="http://codepen.io/KatieK2/pen/tejhz/">KatieK</a></p>
  859. </figcaption>
  860. </figure>
  861. <p>If you don’t want to write the <code>mix</code> function every time, you can create two easy-to-use functions <code>tint</code> and <code>shade</code> (which are also a part of <a href="http://compass-style.org/reference/compass/helpers/colors/#shade">Compass</a>) to do the same thing:</p>
  862. <div class="code-block">
  863. <div class="code-block__wrapper" data-syntax="scss">
  864. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">/// Slightly lighten a color</span>
  865. <span class="c1">/// @access public</span>
  866. <span class="c1">/// @param {Color} $color - color to tint</span>
  867. <span class="c1">/// @param {Number} $percentage - percentage of `$color` in returned color</span>
  868. <span class="c1">/// @return {Color}</span>
  869. <span class="k">@function</span> <span class="nt">tint</span><span class="o">(</span><span class="err">$</span><span class="nt">color</span><span class="o">,</span> <span class="err">$</span><span class="nt">percentage</span><span class="o">)</span> <span class="p">{</span>
  870. <span class="k">@return</span> <span class="nt">mix</span><span class="o">(</span><span class="nt">white</span><span class="o">,</span> <span class="err">$</span><span class="nt">color</span><span class="o">,</span> <span class="err">$</span><span class="nt">percentage</span><span class="o">);</span>
  871. <span class="p">}</span>
  872. <span class="c1">/// Slightly darken a color</span>
  873. <span class="c1">/// @access public</span>
  874. <span class="c1">/// @param {Color} $color - color to shade</span>
  875. <span class="c1">/// @param {Number} $percentage - percentage of `$color` in returned color</span>
  876. <span class="c1">/// @return {Color}</span>
  877. <span class="k">@function</span> <span class="nt">shade</span><span class="o">(</span><span class="err">$</span><span class="nt">color</span><span class="o">,</span> <span class="err">$</span><span class="nt">percentage</span><span class="o">)</span> <span class="p">{</span>
  878. <span class="k">@return</span> <span class="nt">mix</span><span class="o">(</span><span class="nt">black</span><span class="o">,</span> <span class="err">$</span><span class="nt">color</span><span class="o">,</span> <span class="err">$</span><span class="nt">percentage</span><span class="o">);</span>
  879. <span class="p">}</span></code></pre></div>
  880. </div>
  881. <div class="code-block__wrapper" data-syntax="sass">
  882. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">/// Slightly lighten a color</span>
  883. <span class="c1">/// @access public</span>
  884. <span class="c1">/// @param {Color} $color - color to tint</span>
  885. <span class="c1">/// @param {Number} $percentage - percentage of `$color` in returned color</span>
  886. <span class="c1">/// @return {Color}</span>
  887. <span class="k">@function</span> <span class="nt">tint</span><span class="o">(</span><span class="err">$</span><span class="nt">color</span><span class="o">,</span> <span class="err">$</span><span class="nt">percentage</span><span class="o">)</span>
  888. <span class="k">@return</span> <span class="nt">mix</span><span class="o">(</span><span class="err">$</span><span class="nt">color</span><span class="o">,</span> <span class="nt">white</span><span class="o">,</span> <span class="err">$</span><span class="nt">percentage</span><span class="o">)</span>
  889. <span class="c1">/// Slightly darken a color</span>
  890. <span class="c1">/// @access public</span>
  891. <span class="c1">/// @param {Color} $color - color to shade</span>
  892. <span class="c1">/// @param {Number} $percentage - percentage of `$color` in returned color</span>
  893. <span class="c1">/// @return {Color}</span>
  894. <span class="k">@function</span> <span class="nt">shade</span><span class="o">(</span><span class="err">$</span><span class="nt">color</span><span class="o">,</span> <span class="err">$</span><span class="nt">percentage</span><span class="o">)</span>
  895. <span class="k">@return</span> <span class="nt">mix</span><span class="o">(</span><span class="err">$</span><span class="nt">color</span><span class="o">,</span> <span class="nt">black</span><span class="o">,</span> <span class="err">$</span><span class="nt">percentage</span><span class="o">)</span></code></pre></div>
  896. </div>
  897. </div>
  898. <div class="note">
  899. <p>The <a href="http://sass-lang.com/documentation/Sass/Script/Functions.html#scale_color-instance_method"><code>scale-color</code></a> function is designed to scale properties more fluidly by taking into account how high or low they already are. It should provide results that are as nice as <code>mix</code>’s but with a clearer calling convention. The scaling factor isn’t exactly the same though.</p>
  900. </div>
  901. <h6 id="further-reading-7">Further reading</h6>
  902. <h2 id="lists">Lists</h2>
  903. <p>Lists are the Sass equivalent of arrays. A list is a flat data structure (unlike <a href="#maps">maps</a>) intended to store values of any type (including lists, leading to nested lists).</p>
  904. <p>Lists should respect the following guidelines:</p>
  905. <ul>
  906. <li>either inlined or multilines;</li>
  907. <li>necessarily on multilines if too long to fit on an 80-character line;</li>
  908. <li>unless used as is for CSS purposes, always comma separated;</li>
  909. <li>always wrapped in parenthesis;</li>
  910. <li>trailing comma if multilines, not if inlined.</li>
  911. </ul>
  912. <div class="code-block">
  913. <div class="code-block__wrapper" data-syntax="scss">
  914. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Yep</span>
  915. <span class="nv">$font-stack</span><span class="o">:</span> <span class="p">(</span><span class="s1">'</span><span class="s2">Helvetica'</span><span class="o">,</span> <span class="s1">'</span><span class="s2">Arial'</span><span class="o">,</span> <span class="no">sans-serif</span><span class="p">);</span>
  916. <span class="c1">// Yep</span>
  917. <span class="nv">$font-stack</span><span class="o">:</span> <span class="p">(</span>
  918. <span class="s1">'</span><span class="s2">Helvetica'</span><span class="o">,</span>
  919. <span class="s1">'</span><span class="s2">Arial'</span><span class="o">,</span>
  920. <span class="no">sans-serif</span><span class="o">,</span>
  921. <span class="p">);</span>
  922. <span class="c1">// Nope</span>
  923. <span class="nv">$font-stack</span><span class="o">:</span> <span class="s1">'</span><span class="s2">Helvetica'</span> <span class="s1">'</span><span class="s2">Arial'</span> <span class="no">sans-serif</span><span class="p">;</span>
  924. <span class="c1">// Nope</span>
  925. <span class="nv">$font-stack</span><span class="o">:</span> <span class="s1">'</span><span class="s2">Helvetica'</span><span class="o">,</span> <span class="s1">'</span><span class="s2">Arial'</span><span class="o">,</span> <span class="no">sans-serif</span><span class="p">;</span>
  926. <span class="c1">// Nope</span>
  927. <span class="nv">$font-stack</span><span class="o">:</span> <span class="p">(</span><span class="s1">'</span><span class="s2">Helvetica'</span><span class="o">,</span> <span class="s1">'</span><span class="s2">Arial'</span><span class="o">,</span> <span class="no">sans-serif</span><span class="o">,</span><span class="p">);</span></code></pre></div>
  928. </div>
  929. <div class="code-block__wrapper" data-syntax="sass">
  930. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Yep</span>
  931. <span class="na">$font-stack</span><span class="o">:</span> <span class="p">(</span><span class="s1">'</span><span class="s2">Helvetica'</span><span class="o">,</span> <span class="s1">'</span><span class="s2">Arial'</span><span class="o">,</span> <span class="no">sans-serif</span><span class="p">)</span>
  932. <span class="c1">// Nope (not supported)</span>
  933. <span class="na">$font-stack</span><span class="o">:</span> <span class="p">(</span>
  934. <span class="s1">'</span><span class="s2">Helvetica'</span><span class="o">,</span>
  935. <span class="s1">'</span><span class="s2">Arial'</span><span class="o">,</span>
  936. <span class="nt">sans-serif</span><span class="o">,</span>
  937. <span class="o">)</span>
  938. <span class="c1">// Nope</span>
  939. <span class="na">$font-stack</span><span class="o">:</span> <span class="s1">'</span><span class="s2">Helvetica'</span> <span class="s1">'</span><span class="s2">Arial'</span> <span class="no">sans-serif</span>
  940. <span class="c1">// Nope</span>
  941. <span class="na">$font-stack</span><span class="o">:</span> <span class="s1">'</span><span class="s2">Helvetica'</span><span class="o">,</span> <span class="s1">'</span><span class="s2">Arial'</span><span class="o">,</span> <span class="no">sans-serif</span>
  942. <span class="c1">// Nope</span>
  943. <span class="na">$font-stack</span><span class="o">:</span> <span class="p">(</span><span class="s1">'</span><span class="s2">Helvetica'</span><span class="o">,</span> <span class="s1">'</span><span class="s2">Arial'</span><span class="o">,</span> <span class="no">sans-serif</span><span class="o">,</span><span class="p">)</span></code></pre></div>
  944. </div>
  945. </div>
  946. <p>When adding new items to a list, always use the provided API. Do not attempt to add new items manually.</p>
  947. <div class="code-block">
  948. <div class="code-block__wrapper" data-syntax="scss">
  949. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="nv">$shadows</span><span class="o">:</span> <span class="p">(</span><span class="mi">0</span> <span class="mi">42</span><span class="kt">px</span> <span class="mi">13</span><span class="mf">.37</span><span class="kt">px</span> <span class="ni">hotpink</span><span class="p">);</span>
  950. <span class="c1">// Yep</span>
  951. <span class="nv">$shadows</span><span class="o">:</span> <span class="nf">append</span><span class="p">(</span><span class="nv">$shadows</span><span class="o">,</span> <span class="nv">$shadow</span><span class="o">,</span> <span class="n">comma</span><span class="p">);</span>
  952. <span class="c1">// Nope</span>
  953. <span class="nv">$shadows</span><span class="o">:</span> <span class="nv">$shadows</span><span class="o">,</span> <span class="nv">$shadow</span><span class="p">;</span></code></pre></div>
  954. </div>
  955. <div class="code-block__wrapper" data-syntax="sass">
  956. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="nv">$shadows</span><span class="o">:</span> <span class="p">(</span><span class="mi">0</span> <span class="mi">42</span><span class="kt">px</span> <span class="mi">13</span><span class="mf">.37</span><span class="kt">px</span> <span class="ni">hotpink</span><span class="p">)</span>
  957. <span class="c1">// Yep</span>
  958. <span class="nv">$shadows</span><span class="o">:</span> <span class="nf">append</span><span class="p">(</span><span class="nv">$shadows</span><span class="o">,</span> <span class="nv">$shadow</span><span class="o">,</span> <span class="n">comma</span><span class="p">)</span>
  959. <span class="c1">// Nope</span>
  960. <span class="nv">$shadows</span><span class="o">:</span> <span class="nv">$shadows</span><span class="o">,</span> <span class="nv">$shadow</span></code></pre></div>
  961. </div>
  962. </div>
  963. <h6 id="further-reading-8">Further reading</h6>
  964. <h2 id="maps">Maps</h2>
  965. <p>Since Sass 3.3, stylesheet authors can define maps — the Sass term for associative arrays, hashes or even JavaScript objects. A map is a data structure mapping keys (that can be any data type, including maps although I wouldn’t recommend it) to values of any type.</p>
  966. <p>Maps should be written as follows:</p>
  967. <ul>
  968. <li>space after the colon (<code>:</code>);</li>
  969. <li>opening brace (<code>(</code>) on the same line as the colon (<code>:</code>);</li>
  970. <li><strong>quoted keys</strong> if they are strings (which represents 99% of the cases);</li>
  971. <li>each key/value pair on its own new line;</li>
  972. <li>comma (<code>,</code>) at the end of each key/value;</li>
  973. <li><strong>trailing comma</strong> (<code>,</code>) on last item to make it easier to add, remove or reorder items;</li>
  974. <li>closing brace (<code>)</code>) on its own new line;</li>
  975. <li>no space or new line between closing brace (<code>)</code>) and semi-colon (<code>;</code>).</li>
  976. </ul>
  977. <p>Illustration:</p>
  978. <div class="code-block">
  979. <div class="code-block__wrapper" data-syntax="scss">
  980. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Yep</span>
  981. <span class="nv">$breakpoints</span><span class="o">:</span> <span class="p">(</span>
  982. <span class="s1">'</span><span class="s2">small'</span><span class="o">:</span> <span class="mi">767</span><span class="kt">px</span><span class="o">,</span>
  983. <span class="s1">'</span><span class="s2">medium'</span><span class="o">:</span> <span class="mi">992</span><span class="kt">px</span><span class="o">,</span>
  984. <span class="s1">'</span><span class="s2">large'</span><span class="o">:</span> <span class="mi">1200</span><span class="kt">px</span><span class="o">,</span>
  985. <span class="p">);</span>
  986. <span class="c1">// Nope</span>
  987. <span class="nv">$breakpoints</span><span class="o">:</span> <span class="p">(</span> <span class="n">small</span><span class="o">:</span> <span class="mi">767</span><span class="kt">px</span><span class="o">,</span> <span class="no">medium</span><span class="o">:</span> <span class="mi">992</span><span class="kt">px</span><span class="o">,</span> <span class="no">large</span><span class="o">:</span> <span class="mi">1200</span><span class="kt">px</span> <span class="p">);</span></code></pre></div>
  988. </div>
  989. <div class="code-block__wrapper" data-syntax="sass">
  990. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Yep</span>
  991. <span class="nv">$breakpoints</span><span class="o">:</span> <span class="p">(</span><span class="s1">'</span><span class="s2">small'</span><span class="o">:</span> <span class="mi">767</span><span class="kt">px</span><span class="o">,</span> <span class="s1">'</span><span class="s2">medium'</span><span class="o">:</span> <span class="mi">992</span><span class="kt">px</span><span class="o">,</span> <span class="s1">'</span><span class="s2">large'</span><span class="o">:</span> <span class="mi">1200</span><span class="kt">px</span><span class="o">,</span><span class="p">)</span>
  992. <span class="c1">// Nope</span>
  993. <span class="nv">$breakpoints</span><span class="o">:</span> <span class="p">(</span> <span class="s1">'</span><span class="s2">small'</span><span class="o">:</span> <span class="mi">767</span><span class="kt">px</span><span class="o">,</span> <span class="s1">'</span><span class="s2">medium'</span><span class="o">:</span> <span class="mi">992</span><span class="kt">px</span><span class="o">,</span> <span class="s1">'</span><span class="s2">large'</span><span class="o">:</span> <span class="mi">1200</span><span class="kt">px</span> <span class="p">)</span>
  994. <span class="c1">// Nope</span>
  995. <span class="nv">$breakpoints</span><span class="o">:</span> <span class="p">(</span><span class="n">small</span><span class="o">:</span> <span class="mi">767</span><span class="kt">px</span><span class="o">,</span> <span class="no">medium</span><span class="o">:</span> <span class="mi">992</span><span class="kt">px</span><span class="o">,</span> <span class="no">large</span><span class="o">:</span> <span class="mi">1200</span><span class="kt">px</span><span class="o">,</span><span class="p">)</span>
  996. <span class="c1">// Nope (since it is not supported)</span>
  997. <span class="nv">$breakpoints</span><span class="o">:</span> <span class="p">(</span>
  998. <span class="na">'small'</span><span class="o">:</span> <span class="mi">767</span><span class="kt">px</span><span class="o">,</span>
  999. <span class="na">'medium'</span><span class="o">:</span> <span class="mi">992</span><span class="kt">px</span><span class="o">,</span>
  1000. <span class="na">'large'</span><span class="o">:</span> <span class="mi">1200</span><span class="kt">px</span><span class="o">,</span>
  1001. <span class="o">)</span></code></pre></div>
  1002. </div>
  1003. </div>
  1004. <h3 id="debugging-a-sass-map">Debugging a Sass map</h3>
  1005. <p>If you ever find yourself lost, wondering what kind of crazy magic is happening in a Sass map, worry not because there is still a way to be saved.</p>
  1006. <div class="code-block">
  1007. <div class="code-block__wrapper" data-syntax="scss">
  1008. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="k">@mixin</span><span class="nf"> debug-map</span><span class="p">(</span><span class="nv">$map</span><span class="p">)</span> <span class="p">{</span>
  1009. <span class="k">@at-root</span> <span class="p">{</span>
  1010. <span class="k">@debug</span><span class="o">-</span><span class="n">map</span> <span class="p">{</span>
  1011. <span class="na">__toString__</span><span class="o">:</span> <span class="nf">inspect</span><span class="p">(</span><span class="nv">$map</span><span class="p">);</span>
  1012. <span class="na">__length__</span><span class="o">:</span> <span class="nf">length</span><span class="p">(</span><span class="nv">$map</span><span class="p">);</span>
  1013. <span class="na">__depth__</span><span class="o">:</span> <span class="nf">if</span><span class="p">(</span><span class="nf">function-exists</span><span class="p">(</span><span class="s1">'</span><span class="s2">map-depth'</span><span class="p">)</span><span class="o">,</span> <span class="nf">map-depth</span><span class="p">(</span><span class="nv">$map</span><span class="p">)</span><span class="o">,</span> <span class="n">null</span><span class="p">);</span>
  1014. <span class="na">__keys__</span><span class="o">:</span> <span class="nf">map-keys</span><span class="p">(</span><span class="nv">$map</span><span class="p">);</span>
  1015. <span class="nt">__properties__</span> <span class="p">{</span>
  1016. <span class="k">@each</span> <span class="err">$</span><span class="nt">key</span><span class="o">,</span> <span class="err">$</span><span class="nt">value</span> <span class="nt">in</span> <span class="err">$</span><span class="nt">map</span> <span class="p">{</span>
  1017. <span class="nn">#</span><span class="p">{</span><span class="s1">'</span><span class="s2">('</span> <span class="o">+</span> <span class="nt">type-of</span><span class="o">(</span><span class="err">$</span><span class="nt">value</span><span class="o">)</span> <span class="o">+</span> <span class="s1">'</span><span class="s2">) '</span> <span class="o">+</span> <span class="err">$</span><span class="nt">key</span><span class="p">}</span><span class="nd">:</span> <span class="nt">inspect</span><span class="o">(</span><span class="err">$</span><span class="nt">value</span><span class="o">);</span>
  1018. <span class="p">}</span>
  1019. <span class="p">}</span>
  1020. <span class="p">}</span>
  1021. <span class="p">}</span>
  1022. <span class="p">}</span></code></pre></div>
  1023. </div>
  1024. <div class="code-block__wrapper" data-syntax="sass">
  1025. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="nf">=debug-map</span><span class="p">(</span><span class="nv">$map</span><span class="p">)</span>
  1026. <span class="k">@at-root</span>
  1027. <span class="k">@debug</span><span class="o">-</span><span class="n">map</span>
  1028. <span class="na">__toString__</span><span class="o">:</span> <span class="nf">inspect</span><span class="p">(</span><span class="nv">$map</span><span class="p">)</span>
  1029. <span class="na">__length__</span><span class="o">:</span> <span class="nf">length</span><span class="p">(</span><span class="nv">$map</span><span class="p">)</span>
  1030. <span class="na">__depth__</span><span class="o">:</span> <span class="nf">if</span><span class="p">(</span><span class="nf">function-exists</span><span class="p">(</span><span class="s1">'</span><span class="s2">map-depth'</span><span class="p">)</span><span class="o">,</span> <span class="nf">map-depth</span><span class="p">(</span><span class="nv">$map</span><span class="p">)</span><span class="o">,</span> <span class="n">null</span><span class="p">)</span>
  1031. <span class="na">__keys__</span><span class="o">:</span> <span class="nf">map-keys</span><span class="p">(</span><span class="nv">$map</span><span class="p">)</span>
  1032. <span class="nt">__properties__</span>
  1033. <span class="k">@each</span> <span class="err">$</span><span class="nt">key</span><span class="o">,</span> <span class="err">$</span><span class="nt">value</span> <span class="nt">in</span> <span class="err">$</span><span class="nt">map</span>
  1034. <span class="na">#{'('</span><span class="err"> </span><span class="na">+</span><span class="err"> </span><span class="na">type-of($value)</span><span class="err"> </span><span class="na">+</span><span class="err"> </span><span class="na">')</span><span class="err"> </span><span class="na">'</span><span class="err"> </span><span class="na">+</span><span class="err"> </span><span class="na">$key}</span><span class="o">:</span> <span class="nf">inspect</span><span class="p">(</span><span class="nv">$value</span><span class="p">)</span></code></pre></div>
  1035. </div>
  1036. </div>
  1037. <p>If you are interested in knowing the depth of the map, add the following function. The mixin will display it automatically.</p>
  1038. <div class="code-block">
  1039. <div class="code-block__wrapper" data-syntax="scss">
  1040. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">/// Compute the maximum depth of a map</span>
  1041. <span class="c1">/// @param {Map} $map</span>
  1042. <span class="c1">/// @return {Number} max depth of `$map`</span>
  1043. <span class="k">@function</span> <span class="nt">map-depth</span><span class="o">(</span><span class="err">$</span><span class="nt">map</span><span class="o">)</span> <span class="p">{</span>
  1044. <span class="nv">$level</span><span class="o">:</span> <span class="mi">1</span><span class="p">;</span>
  1045. <span class="k">@each</span> <span class="err">$</span><span class="nt">key</span><span class="o">,</span> <span class="err">$</span><span class="nt">value</span> <span class="nt">in</span> <span class="err">$</span><span class="nt">map</span> <span class="p">{</span>
  1046. <span class="k">@if</span> <span class="nf">type-of</span><span class="p">(</span><span class="nv">$value</span><span class="p">)</span> <span class="o">==</span> <span class="s1">'</span><span class="s2">map'</span> <span class="p">{</span>
  1047. <span class="nv">$level</span><span class="o">:</span> <span class="nf">max</span><span class="p">(</span><span class="nf">map-depth</span><span class="p">(</span><span class="nv">$value</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="o">,</span> <span class="nv">$level</span><span class="p">);</span>
  1048. <span class="p">}</span>
  1049. <span class="p">}</span>
  1050. <span class="k">@return</span> <span class="err">$</span><span class="nt">level</span><span class="o">;</span>
  1051. <span class="p">}</span></code></pre></div>
  1052. </div>
  1053. <div class="code-block__wrapper" data-syntax="sass">
  1054. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">/// Compute the maximum depth of a map</span>
  1055. <span class="c1">/// @param {Map} $map</span>
  1056. <span class="c1">/// @return {Number} max depth of `$map`</span>
  1057. <span class="k">@function</span> <span class="nt">map-depth</span><span class="o">(</span><span class="err">$</span><span class="nt">map</span><span class="o">)</span>
  1058. <span class="nv">$level</span><span class="o">:</span> <span class="mi">1</span>
  1059. <span class="k">@each</span> <span class="err">$</span><span class="nt">key</span><span class="o">,</span> <span class="err">$</span><span class="nt">value</span> <span class="nt">in</span> <span class="err">$</span><span class="nt">map</span>
  1060. <span class="k">@if</span> <span class="nf">type-of</span><span class="p">(</span><span class="nv">$value</span><span class="p">)</span> <span class="o">==</span> <span class="s1">'</span><span class="s2">map'</span>
  1061. <span class="nv">$level</span><span class="o">:</span> <span class="nf">max</span><span class="p">(</span><span class="nf">map-depth</span><span class="p">(</span><span class="nv">$value</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="o">,</span> <span class="nv">$level</span><span class="p">)</span>
  1062. <span class="k">@return</span> <span class="err">$</span><span class="nt">level</span><span class="o">;</span></code></pre></div>
  1063. </div>
  1064. </div>
  1065. <h6 id="further-reading-9">Further reading</h6>
  1066. <h2 id="css-ruleset">CSS Ruleset</h2>
  1067. <p>At this point, this is mostly revising what everybody knows, but here is how a CSS ruleset should be written (at least, according to most guidelines, including <a href="http://cssguidelin.es/#anatomy-of-a-ruleset">CSS Guidelines</a>):</p>
  1068. <ul>
  1069. <li>related selectors on the same line; unrelated selectors on new lines;</li>
  1070. <li>the opening brace (<code>{</code>) spaced from the last selector by a single space;</li>
  1071. <li>each declaration on its own new line;</li>
  1072. <li>a space after the colon (<code>:</code>);</li>
  1073. <li>a trailing semi-colon (<code>;</code>) at the end of all declarations;</li>
  1074. <li>the closing brace (<code>}</code>) on its own new line;</li>
  1075. <li>a new line after the closing brace <code>}</code>.</li>
  1076. </ul>
  1077. <p>Illustration:</p>
  1078. <div class="code-block">
  1079. <div class="code-block__wrapper" data-syntax="scss">
  1080. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Yep</span>
  1081. <span class="nc">.foo</span><span class="o">,</span> <span class="nc">.foo-bar</span><span class="o">,</span>
  1082. <span class="nc">.baz</span> <span class="p">{</span>
  1083. <span class="na">display</span><span class="o">:</span> <span class="no">block</span><span class="p">;</span>
  1084. <span class="na">overflow</span><span class="o">:</span> <span class="no">hidden</span><span class="p">;</span>
  1085. <span class="na">margin</span><span class="o">:</span> <span class="mi">0</span> <span class="no">auto</span><span class="p">;</span>
  1086. <span class="p">}</span>
  1087. <span class="c1">// Nope</span>
  1088. <span class="nc">.foo</span><span class="o">,</span>
  1089. <span class="nc">.foo-bar</span><span class="o">,</span> <span class="nc">.baz</span> <span class="p">{</span>
  1090. <span class="na">display</span><span class="o">:</span> <span class="no">block</span><span class="p">;</span>
  1091. <span class="na">overflow</span><span class="o">:</span> <span class="no">hidden</span><span class="p">;</span>
  1092. <span class="na">margin</span><span class="o">:</span> <span class="mi">0</span> <span class="no">auto</span> <span class="p">}</span></code></pre></div>
  1093. </div>
  1094. <div class="code-block__wrapper" data-syntax="sass">
  1095. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Yep</span>
  1096. <span class="nc">.foo</span><span class="o">,</span> <span class="nc">.foo-bar</span><span class="o">,</span>
  1097. <span class="nc">.baz</span>
  1098. <span class="na">display</span><span class="o">:</span> <span class="no">block</span>
  1099. <span class="na">overflow</span><span class="o">:</span> <span class="no">hidden</span>
  1100. <span class="na">margin</span><span class="o">:</span> <span class="mi">0</span> <span class="no">auto</span>
  1101. <span class="c1">// Nope</span>
  1102. <span class="nc">.foo</span><span class="o">,</span>
  1103. <span class="nc">.foo-bar</span><span class="o">,</span> <span class="nc">.baz</span>
  1104. <span class="na">display</span><span class="o">:</span> <span class="no">block</span>
  1105. <span class="na">overflow</span><span class="o">:</span> <span class="no">hidden</span>
  1106. <span class="na">margin</span><span class="o">:</span> <span class="mi">0</span> <span class="no">auto</span></code></pre></div>
  1107. </div>
  1108. </div>
  1109. <p>Adding to those CSS-related guidelines, we want to pay attention to:</p>
  1110. <ul>
  1111. <li>local variables being declared before any declarations, then spaced from declarations by a new line;</li>
  1112. <li>mixin calls with no <code>@content</code> coming before any declaration;</li>
  1113. <li>nested selectors always coming after a new line;</li>
  1114. <li>mixin calls with <code>@content</code> coming after any nested selector;</li>
  1115. <li>no new line before a closing brace (<code>}</code>).</li>
  1116. </ul>
  1117. <p>Illustration:</p>
  1118. <div class="code-block">
  1119. <div class="code-block__wrapper" data-syntax="scss">
  1120. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="nc">.foo</span><span class="o">,</span> <span class="nc">.foo-bar</span><span class="o">,</span>
  1121. <span class="nc">.baz</span> <span class="p">{</span>
  1122. <span class="nv">$length</span><span class="o">:</span> <span class="mi">42</span><span class="kt">em</span><span class="p">;</span>
  1123. <span class="k">@include</span><span class="nd"> ellipsis</span><span class="p">;</span>
  1124. <span class="k">@include</span><span class="nd"> size</span><span class="p">(</span><span class="nv">$length</span><span class="p">);</span>
  1125. <span class="na">display</span><span class="o">:</span> <span class="no">block</span><span class="p">;</span>
  1126. <span class="na">overflow</span><span class="o">:</span> <span class="no">hidden</span><span class="p">;</span>
  1127. <span class="na">margin</span><span class="o">:</span> <span class="mi">0</span> <span class="no">auto</span><span class="p">;</span>
  1128. <span class="k">&amp;</span><span class="nd">:hover</span> <span class="p">{</span>
  1129. <span class="na">color</span><span class="o">:</span> <span class="nb">red</span><span class="p">;</span>
  1130. <span class="p">}</span>
  1131. <span class="k">@include</span><span class="nd"> respond-to</span><span class="p">(</span><span class="s1">'</span><span class="s2">small'</span><span class="p">)</span> <span class="p">{</span>
  1132. <span class="na">overflow</span><span class="o">:</span> <span class="no">visible</span><span class="p">;</span>
  1133. <span class="p">}</span>
  1134. <span class="p">}</span></code></pre></div>
  1135. </div>
  1136. <div class="code-block__wrapper" data-syntax="sass">
  1137. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="nc">.foo</span><span class="o">,</span> <span class="nc">.foo-bar</span><span class="o">,</span>
  1138. <span class="nc">.baz</span>
  1139. <span class="nv">$length</span><span class="o">:</span> <span class="mi">42</span><span class="kt">em</span>
  1140. <span class="nd">+ellipsis</span>
  1141. <span class="nd">+size</span><span class="p">(</span><span class="nv">$length</span><span class="p">)</span>
  1142. <span class="na">display</span><span class="o">:</span> <span class="no">block</span>
  1143. <span class="na">overflow</span><span class="o">:</span> <span class="no">hidden</span>
  1144. <span class="na">margin</span><span class="o">:</span> <span class="mi">0</span> <span class="no">auto</span>
  1145. <span class="k">&amp;</span><span class="nd">:hover</span>
  1146. <span class="na">color</span><span class="o">:</span> <span class="nb">red</span>
  1147. <span class="nd">+respond-to</span><span class="p">(</span><span class="s1">'</span><span class="s2">small'</span><span class="p">)</span>
  1148. <span class="na">overflow</span><span class="o">:</span> <span class="no">visible</span></code></pre></div>
  1149. </div>
  1150. </div>
  1151. <h6 id="further-reading-10">Further reading</h6>
  1152. <h2 id="declaration-sorting">Declaration Sorting</h2>
  1153. <p>I cannot think of many topics where opinions are as divided as they are regarding declaration sorting in CSS. Concretely, there are two factions here:</p>
  1154. <ul>
  1155. <li>sticking to the alphabetical order;</li>
  1156. <li>ordering declarations by type (position, display, colors, font, miscellaneous…).</li>
  1157. </ul>
  1158. <p>There are pros and cons for both ways. On one hand, alphabetical order is universal (at least for languages using the latin alphabet) so there is no argument about sorting one property before another. However, it seems extremely weird to me to see properties such as <code>bottom</code> and <code>top</code> not right next to each other. Why would animations should appear before the display type? There are a lot of oddities with alphabetical ordering.</p>
  1159. <div class="code-block">
  1160. <div class="code-block__wrapper" data-syntax="scss">
  1161. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="nc">.foo</span> <span class="p">{</span>
  1162. <span class="na">background</span><span class="o">:</span> <span class="nb">black</span><span class="p">;</span>
  1163. <span class="na">bottom</span><span class="o">:</span> <span class="mi">0</span><span class="p">;</span>
  1164. <span class="na">color</span><span class="o">:</span> <span class="nb">white</span><span class="p">;</span>
  1165. <span class="na">font-weight</span><span class="o">:</span> <span class="no">bold</span><span class="p">;</span>
  1166. <span class="na">font-size</span><span class="o">:</span> <span class="mi">1</span><span class="mf">.5</span><span class="kt">em</span><span class="p">;</span>
  1167. <span class="na">height</span><span class="o">:</span> <span class="mi">100</span><span class="kt">px</span><span class="p">;</span>
  1168. <span class="na">overflow</span><span class="o">:</span> <span class="no">hidden</span><span class="p">;</span>
  1169. <span class="na">position</span><span class="o">:</span> <span class="no">absolute</span><span class="p">;</span>
  1170. <span class="na">right</span><span class="o">:</span> <span class="mi">0</span><span class="p">;</span>
  1171. <span class="na">width</span><span class="o">:</span> <span class="mi">100</span><span class="kt">px</span><span class="p">;</span>
  1172. <span class="p">}</span></code></pre></div>
  1173. </div>
  1174. <div class="code-block__wrapper" data-syntax="sass">
  1175. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="nc">.foo</span>
  1176. <span class="na">background</span><span class="o">:</span> <span class="nb">black</span>
  1177. <span class="na">bottom</span><span class="o">:</span> <span class="mi">0</span>
  1178. <span class="na">color</span><span class="o">:</span> <span class="nb">white</span>
  1179. <span class="na">font-weight</span><span class="o">:</span> <span class="no">bold</span>
  1180. <span class="na">font-size</span><span class="o">:</span> <span class="mi">1</span><span class="mf">.5</span><span class="kt">em</span>
  1181. <span class="na">height</span><span class="o">:</span> <span class="mi">100</span><span class="kt">px</span>
  1182. <span class="na">overflow</span><span class="o">:</span> <span class="no">hidden</span>
  1183. <span class="na">position</span><span class="o">:</span> <span class="no">absolute</span>
  1184. <span class="na">right</span><span class="o">:</span> <span class="mi">0</span>
  1185. <span class="na">width</span><span class="o">:</span> <span class="mi">100</span><span class="kt">px</span></code></pre></div>
  1186. </div>
  1187. </div>
  1188. <p>On the other hand, ordering properties by type makes perfect sense. Every font-related declarations are gathered, <code>top</code> and <code>bottom</code> are reunited and reading a ruleset kind of feels like reading a short story. But unless you stick to some conventions like <a href="https://github.com/necolas/idiomatic-css">Idiomatic CSS</a>, there is a lot of room for interpretation in this way of doing things. Where would <code>white-space</code> go: font or display? Where does belong <code>overflow</code> exactly? What is the property order within a group (it could be alphabetically, oh the irony)?</p>
  1189. <div class="code-block">
  1190. <div class="code-block__wrapper" data-syntax="scss">
  1191. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="nc">.foo</span> <span class="p">{</span>
  1192. <span class="na">height</span><span class="o">:</span> <span class="mi">100</span><span class="kt">px</span><span class="p">;</span>
  1193. <span class="na">width</span><span class="o">:</span> <span class="mi">100</span><span class="kt">px</span><span class="p">;</span>
  1194. <span class="na">overflow</span><span class="o">:</span> <span class="no">hidden</span><span class="p">;</span>
  1195. <span class="na">position</span><span class="o">:</span> <span class="no">absolute</span><span class="p">;</span>
  1196. <span class="na">bottom</span><span class="o">:</span> <span class="mi">0</span><span class="p">;</span>
  1197. <span class="na">right</span><span class="o">:</span> <span class="mi">0</span><span class="p">;</span>
  1198. <span class="na">background</span><span class="o">:</span> <span class="nb">black</span><span class="p">;</span>
  1199. <span class="na">color</span><span class="o">:</span> <span class="nb">white</span><span class="p">;</span>
  1200. <span class="na">font-weight</span><span class="o">:</span> <span class="no">bold</span><span class="p">;</span>
  1201. <span class="na">font-size</span><span class="o">:</span> <span class="mi">1</span><span class="mf">.5</span><span class="kt">em</span><span class="p">;</span>
  1202. <span class="p">}</span></code></pre></div>
  1203. </div>
  1204. <div class="code-block__wrapper" data-syntax="sass">
  1205. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="nc">.foo</span>
  1206. <span class="na">height</span><span class="o">:</span> <span class="mi">100</span><span class="kt">px</span>
  1207. <span class="na">width</span><span class="o">:</span> <span class="mi">100</span><span class="kt">px</span>
  1208. <span class="na">overflow</span><span class="o">:</span> <span class="no">hidden</span>
  1209. <span class="na">position</span><span class="o">:</span> <span class="no">absolute</span>
  1210. <span class="na">bottom</span><span class="o">:</span> <span class="mi">0</span>
  1211. <span class="na">right</span><span class="o">:</span> <span class="mi">0</span>
  1212. <span class="na">background</span><span class="o">:</span> <span class="nb">black</span>
  1213. <span class="na">color</span><span class="o">:</span> <span class="nb">white</span>
  1214. <span class="na">font-weight</span><span class="o">:</span> <span class="no">bold</span>
  1215. <span class="na">font-size</span><span class="o">:</span> <span class="mi">1</span><span class="mf">.5</span><span class="kt">em</span></code></pre></div>
  1216. </div>
  1217. </div>
  1218. <p>There is also another interesting subtree of type ordering called <a href="https://github.com/brandon-rhodes/Concentric-CSS">Concentric CSS</a>, that seems to be quite popular as well. Basically, Concentric CSS relies on the box-model to define an order: starts outside, moves inward.</p>
  1219. <div class="code-block">
  1220. <div class="code-block__wrapper" data-syntax="scss">
  1221. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="nc">.foo</span> <span class="p">{</span>
  1222. <span class="na">width</span><span class="o">:</span> <span class="mi">100</span><span class="kt">px</span><span class="p">;</span>
  1223. <span class="na">height</span><span class="o">:</span> <span class="mi">100</span><span class="kt">px</span><span class="p">;</span>
  1224. <span class="na">position</span><span class="o">:</span> <span class="no">absolute</span><span class="p">;</span>
  1225. <span class="na">right</span><span class="o">:</span> <span class="mi">0</span><span class="p">;</span>
  1226. <span class="na">bottom</span><span class="o">:</span> <span class="mi">0</span><span class="p">;</span>
  1227. <span class="na">background</span><span class="o">:</span> <span class="nb">black</span><span class="p">;</span>
  1228. <span class="na">overflow</span><span class="o">:</span> <span class="no">hidden</span><span class="p">;</span>
  1229. <span class="na">color</span><span class="o">:</span> <span class="nb">white</span><span class="p">;</span>
  1230. <span class="na">font-weight</span><span class="o">:</span> <span class="no">bold</span><span class="p">;</span>
  1231. <span class="na">font-size</span><span class="o">:</span> <span class="mi">1</span><span class="mf">.5</span><span class="kt">em</span><span class="p">;</span>
  1232. <span class="p">}</span></code></pre></div>
  1233. </div>
  1234. <div class="code-block__wrapper" data-syntax="sass">
  1235. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="nc">.foo</span>
  1236. <span class="na">width</span><span class="o">:</span> <span class="mi">100</span><span class="kt">px</span>
  1237. <span class="na">height</span><span class="o">:</span> <span class="mi">100</span><span class="kt">px</span>
  1238. <span class="na">position</span><span class="o">:</span> <span class="no">absolute</span>
  1239. <span class="na">right</span><span class="o">:</span> <span class="mi">0</span>
  1240. <span class="na">bottom</span><span class="o">:</span> <span class="mi">0</span>
  1241. <span class="na">background</span><span class="o">:</span> <span class="nb">black</span>
  1242. <span class="na">overflow</span><span class="o">:</span> <span class="no">hidden</span>
  1243. <span class="na">color</span><span class="o">:</span> <span class="nb">white</span>
  1244. <span class="na">font-weight</span><span class="o">:</span> <span class="no">bold</span>
  1245. <span class="na">font-size</span><span class="o">:</span> <span class="mi">1</span><span class="mf">.5</span><span class="kt">em</span></code></pre></div>
  1246. </div>
  1247. </div>
  1248. <p>I must say I cannot decide myself. A <a href="http://css-tricks.com/poll-results-how-do-you-order-your-css-properties/">recent poll on CSS-Tricks</a> determined that over 45% developers order their declarations by type against 14% alphabetically. Also, there are 39% that go full random, including myself.</p>
  1249. <figure role="group">
  1250. <img src="http://sass-guidelin.es/assets/images/css-order-chart.png" alt="Chart showing how developers order their CSS declarations&#10;"/>
  1251. <figcaption><p>Chart showing how developers order their CSS declarations</p>
  1252. </figcaption>
  1253. </figure>
  1254. <p>Because of this, I will not impose a choice in this styleguide. Pick the one you prefer, as long as you are consistent throughout your stylesheets (i.e. not the <em>random</em> option).</p>
  1255. <div class="note">
  1256. <p>A <a href="http://peteschuster.com/2014/12/reduce-file-size-css-sorting/">recent study</a> shows that using <a href="https://github.com/csscomb/csscomb.js">CSS Comb</a> (which uses <a href="https://github.com/csscomb/csscomb.js/blob/master/config/csscomb.json">type ordering</a>) for sorting CSS declarations ends up shortening the average file size under Gzip compression by 2.7%, compared to 1.3% when sorting alphabetically.</p>
  1257. </div>
  1258. <h6 id="further-reading-11">Further reading</h6>
  1259. <h2 id="selector-nesting">Selector Nesting</h2>
  1260. <p>One particular feature Sass provides that is being overly misused by many developers is <em>selector nesting</em>. Selector nesting offers a way for stylesheet authors to compute long selectors by nesting shorter selectors within each others.</p>
  1261. <h3 id="general-rule">General rule</h3>
  1262. <p>For instance, the following Sass nesting:</p>
  1263. <div class="code-block">
  1264. <div class="code-block__wrapper" data-syntax="scss">
  1265. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="nc">.foo</span> <span class="p">{</span>
  1266. <span class="nc">.bar</span> <span class="p">{</span>
  1267. <span class="k">&amp;</span><span class="nd">:hover</span> <span class="p">{</span>
  1268. <span class="na">color</span><span class="o">:</span> <span class="nb">red</span><span class="p">;</span>
  1269. <span class="p">}</span>
  1270. <span class="p">}</span>
  1271. <span class="p">}</span></code></pre></div>
  1272. </div>
  1273. <div class="code-block__wrapper" data-syntax="sass">
  1274. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="nc">.foo</span>
  1275. <span class="nc">.bar</span>
  1276. <span class="k">&amp;</span><span class="nd">:hover</span>
  1277. <span class="na">color</span><span class="o">:</span> <span class="nb">red</span></code></pre></div>
  1278. </div>
  1279. </div>
  1280. <p>… will generate this CSS:</p>
  1281. <div>
  1282. <div class="highlight"><pre><code class="language-css" data-lang="css"><span class="nc">.foo</span> <span class="nc">.bar</span><span class="nd">:hover</span> <span class="p">{</span>
  1283. <span class="k">color</span><span class="o">:</span> <span class="nb">red</span><span class="p">;</span>
  1284. <span class="p">}</span></code></pre></div>
  1285. </div>
  1286. <p>Along the same lines, since Sass 3.3 it is possible to use the current selector reference (<code>&amp;</code>) to generate advanced selectors. For instance:</p>
  1287. <div class="code-block">
  1288. <div class="code-block__wrapper" data-syntax="scss">
  1289. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="nc">.foo</span> <span class="p">{</span>
  1290. <span class="k">&amp;</span><span class="nt">-bar</span> <span class="p">{</span>
  1291. <span class="na">color</span><span class="o">:</span> <span class="nb">red</span><span class="p">;</span>
  1292. <span class="p">}</span>
  1293. <span class="p">}</span></code></pre></div>
  1294. </div>
  1295. </div>
  1296. <p>… will generate this CSS:</p>
  1297. <p>This method is often used along with <a href="http://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem-syntax/">BEM naming conventions</a> to generate <code>.block__element</code> and <code>.block--modifier</code> selectors based on the original selector (i.e. <code>.block</code> in this case).</p>
  1298. <div class="note">
  1299. <p>While it might be anecdotal, generating new selectors from the current selector reference (<code>&amp;</code>) makes those selectors unsearchable in the codebase since they do not exist per se.</p>
  1300. </div>
  1301. <p>The problem with selector nesting is that it ultimately makes code more difficult to read. One has to mentally compute the resulting selector out of the indentation levels; it is not always quite obvious what the CSS will end up being.</p>
  1302. <p>This statement becomes truer as selectors get longer and references to the current selector (<code>&amp;</code>) more frequent. At some point, the risk of losing track and not being able to understand what’s going on anymore is so high that it is not worth it.</p>
  1303. <p>To prevent such a situation, we <strong>avoid selector nesting as much as possible</strong>. However, there are obviously a few exceptions to this rule.</p>
  1304. <h3 id="exceptions">Exceptions</h3>
  1305. <p>For starters, it is allowed and even recommended to nest pseudo-classes and pseudo-elements within the initial selector.</p>
  1306. <div class="code-block">
  1307. <div class="code-block__wrapper" data-syntax="scss">
  1308. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="nc">.foo</span> <span class="p">{</span>
  1309. <span class="na">color</span><span class="o">:</span> <span class="nb">red</span><span class="p">;</span>
  1310. <span class="k">&amp;</span><span class="nd">:hover</span> <span class="p">{</span>
  1311. <span class="na">color</span><span class="o">:</span> <span class="nb">green</span><span class="p">;</span>
  1312. <span class="p">}</span>
  1313. <span class="na">&amp;</span><span class="o">::</span><span class="n">before</span> <span class="p">{</span>
  1314. <span class="na">content</span><span class="o">:</span> <span class="s1">'</span><span class="s2">pseudo-element'</span><span class="p">;</span>
  1315. <span class="p">}</span>
  1316. <span class="p">}</span></code></pre></div>
  1317. </div>
  1318. <div class="code-block__wrapper" data-syntax="sass">
  1319. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="nc">.foo</span>
  1320. <span class="na">color</span><span class="o">:</span> <span class="nb">red</span>
  1321. <span class="k">&amp;</span><span class="nd">:hover</span>
  1322. <span class="na">color</span><span class="o">:</span> <span class="nb">green</span>
  1323. <span class="na">&amp;</span><span class="o">::</span><span class="n">before</span>
  1324. <span class="na">content</span><span class="o">:</span> <span class="s1">'</span><span class="s2">pseudo-element'</span></code></pre></div>
  1325. </div>
  1326. </div>
  1327. <p>Using selector nesting for pseudo-classes and pseudo-elements not only makes sense (because it deals with closely related selectors), it also helps keep everything about a component at the same place.</p>
  1328. <p>Also, when using component-agnostic state classes such as <code>.is-active</code>, it is perfectly fine to nest it under the component’s selector to keep things tidy.</p>
  1329. <div class="code-block">
  1330. <div class="code-block__wrapper" data-syntax="scss">
  1331. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="nc">.foo</span> <span class="p">{</span>
  1332. <span class="c1">// ...</span>
  1333. <span class="k">&amp;</span><span class="nc">.is-active</span> <span class="p">{</span>
  1334. <span class="na">font-weight</span><span class="o">:</span> <span class="no">bold</span><span class="p">;</span>
  1335. <span class="p">}</span>
  1336. <span class="p">}</span></code></pre></div>
  1337. </div>
  1338. <div class="code-block__wrapper" data-syntax="sass">
  1339. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="nc">.foo</span>
  1340. <span class="c1">// ...</span>
  1341. <span class="k">&amp;</span><span class="nc">.is-active</span>
  1342. <span class="na">font-weight</span><span class="o">:</span> <span class="no">bold</span></code></pre></div>
  1343. </div>
  1344. </div>
  1345. <p>Last but not least, when styling an element because it happens to be contained within another specific element, it is also fine to use nesting to keep everything about the component at the same place.</p>
  1346. <div class="code-block">
  1347. <div class="code-block__wrapper" data-syntax="scss">
  1348. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="nc">.foo</span> <span class="p">{</span>
  1349. <span class="c1">// ...</span>
  1350. <span class="nc">.no-opacity</span> <span class="k">&amp;</span> <span class="p">{</span>
  1351. <span class="na">display</span><span class="o">:</span> <span class="no">none</span><span class="p">;</span>
  1352. <span class="p">}</span>
  1353. <span class="p">}</span></code></pre></div>
  1354. </div>
  1355. <div class="code-block__wrapper" data-syntax="sass">
  1356. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="nc">.foo</span>
  1357. <span class="c1">// ...</span>
  1358. <span class="nc">.no-opacity</span> <span class="k">&amp;</span>
  1359. <span class="na">display</span><span class="o">:</span> <span class="no">none</span></code></pre></div>
  1360. </div>
  1361. </div>
  1362. <p>When working with unexperienced developers, a selector such as <code>.no-opacity &amp;</code> might look a little weird. To prevent any confusion, you can build a very short mixin that transform this odd syntax into an explicit API.</p>
  1363. <div class="code-block">
  1364. <div class="code-block__wrapper" data-syntax="scss">
  1365. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">/// Helper mixin to provide simple API to selector nesting</span>
  1366. <span class="c1">/// @param {String} $selector - Selector</span>
  1367. <span class="k">@mixin</span><span class="nf"> when-inside</span><span class="p">(</span><span class="nv">$selector</span><span class="p">)</span> <span class="p">{</span>
  1368. <span class="nn">#</span><span class="p">{</span><span class="err">$</span><span class="nt">selector</span><span class="p">}</span> <span class="k">&amp;</span> <span class="p">{</span>
  1369. <span class="k">@content</span><span class="o">;</span>
  1370. <span class="p">}</span>
  1371. <span class="p">}</span></code></pre></div>
  1372. </div>
  1373. <div class="code-block__wrapper" data-syntax="sass">
  1374. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">/// Helper mixin to provide simple API to selector nesting</span>
  1375. <span class="c1">/// @param {String} $selector - Selector</span>
  1376. <span class="nf">=when-inside</span><span class="p">(</span><span class="nv">$selector</span><span class="p">)</span> <span class="err">{</span>
  1377. <span class="nn">#</span><span class="err">{$</span><span class="nt">selector</span><span class="err">}</span> <span class="k">&amp;</span>
  1378. <span class="k">@content</span>
  1379. <span class="err">}</span></code></pre></div>
  1380. </div>
  1381. </div>
  1382. <p>Rewriting our previous example, it would look like this:</p>
  1383. <div class="code-block">
  1384. <div class="code-block__wrapper" data-syntax="scss">
  1385. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="nc">.foo</span> <span class="p">{</span>
  1386. <span class="c1">// ...</span>
  1387. <span class="k">@include</span><span class="nd"> when-inside</span><span class="p">(</span><span class="s1">'</span><span class="s2">.no-opacity'</span><span class="p">)</span> <span class="p">{</span>
  1388. <span class="na">display</span><span class="o">:</span> <span class="no">none</span><span class="p">;</span>
  1389. <span class="p">}</span>
  1390. <span class="p">}</span></code></pre></div>
  1391. </div>
  1392. <div class="code-block__wrapper" data-syntax="sass">
  1393. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="nc">.foo</span>
  1394. <span class="c1">// ...</span>
  1395. <span class="nd">+when-inside</span><span class="p">(</span><span class="s1">'</span><span class="s2">.no-opacity'</span><span class="p">)</span>
  1396. <span class="na">display</span><span class="o">:</span> <span class="no">none</span></code></pre></div>
  1397. </div>
  1398. </div>
  1399. <p>As with everything, the specifics are somewhat irrelevant, consistency is key. If you feel fully confident with selector nesting, then use selector nesting. Just make sure your whole team is okay with that.</p>
  1400. <h6 id="further-reading-12">Further reading</h6>
  1401. <h1 id="naming-conventions">Naming conventions</h1>
  1402. <p>In this section, we will not deal with the best CSS naming conventions for maintainability and scale; not only is that up to you, it’s also out of the scope of a Sass styleguide. I suggest those recommended by <a href="http://cssguidelin.es/#naming-conventions">CSS Guidelines</a>.</p>
  1403. <p>There are a few things you can name in Sass, and it is important to name them well so the whole code base looks both consistent and easy to read:</p>
  1404. <ul>
  1405. <li>variables;</li>
  1406. <li>functions;</li>
  1407. <li>mixins.</li>
  1408. </ul>
  1409. <p>Sass placeholders are deliberately omitted from this list since they can be considered as regular CSS selectors, thus following the same naming pattern as classes.</p>
  1410. <p>Regarding variables, functions and mixins, we stick to something very <em>CSS-y</em>: <strong>lowercase hyphen-delimited</strong>, and above all meaningful.</p>
  1411. <div class="code-block">
  1412. <div class="code-block__wrapper" data-syntax="scss">
  1413. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="nv">$vertical-rhythm-baseline</span><span class="o">:</span> <span class="mi">1</span><span class="mf">.5</span><span class="kt">rem</span><span class="p">;</span>
  1414. <span class="k">@mixin</span><span class="nf"> size</span><span class="p">(</span><span class="nv">$width</span><span class="o">,</span> <span class="nv">$height</span><span class="o">:</span> <span class="nv">$width</span><span class="p">)</span> <span class="p">{</span>
  1415. <span class="c1">// ...</span>
  1416. <span class="p">}</span>
  1417. <span class="k">@function</span> <span class="nt">opposite-direction</span><span class="o">(</span><span class="err">$</span><span class="nt">direction</span><span class="o">)</span> <span class="p">{</span>
  1418. <span class="c1">// ...</span>
  1419. <span class="p">}</span></code></pre></div>
  1420. </div>
  1421. <div class="code-block__wrapper" data-syntax="sass">
  1422. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="na">$vertical-rhythm-baseline</span><span class="o">:</span> <span class="mi">1</span><span class="mf">.5</span><span class="kt">rem</span>
  1423. <span class="nf">=size</span><span class="p">(</span><span class="nv">$width</span><span class="o">,</span> <span class="nv">$height</span><span class="o">:</span> <span class="nv">$width</span><span class="p">)</span>
  1424. <span class="c1">// ...</span>
  1425. <span class="k">@function</span> <span class="nt">opposite-direction</span><span class="o">(</span><span class="err">$</span><span class="nt">direction</span><span class="o">)</span>
  1426. <span class="c1">// ...</span></code></pre></div>
  1427. </div>
  1428. </div>
  1429. <h6 id="further-reading-13">Further reading</h6>
  1430. <h2 id="constants">Constants</h2>
  1431. <p>If you happen to be a framework developer or library writer, you might find yourself dealing with variables that are not meant to be updated in any circumstances: constants. Unfortunately (or fortunately?), Sass does not provide any way to define such entities, so we have to stick to strict naming conventions to make our point.</p>
  1432. <p>As for many languages, I suggest all-caps snakerized variables when they are constants. Not only is this a very old convention, but it also contrasts well with usual lowercased hyphenated variables.</p>
  1433. <div class="code-block">
  1434. <div class="code-block__wrapper" data-syntax="scss">
  1435. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Yep</span>
  1436. <span class="nv">$CSS_POSITIONS</span><span class="o">:</span> <span class="p">(</span><span class="no">top</span><span class="o">,</span> <span class="no">right</span><span class="o">,</span> <span class="no">bottom</span><span class="o">,</span> <span class="no">left</span><span class="o">,</span> <span class="no">center</span><span class="p">);</span>
  1437. <span class="c1">// Nope</span>
  1438. <span class="nv">$css-positions</span><span class="o">:</span> <span class="p">(</span><span class="no">top</span><span class="o">,</span> <span class="no">right</span><span class="o">,</span> <span class="no">bottom</span><span class="o">,</span> <span class="no">left</span><span class="o">,</span> <span class="no">center</span><span class="p">);</span></code></pre></div>
  1439. </div>
  1440. <div class="code-block__wrapper" data-syntax="sass">
  1441. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Yep</span>
  1442. <span class="nv">$CSS_POSITIONS</span><span class="o">:</span> <span class="p">(</span><span class="no">top</span><span class="o">,</span> <span class="no">right</span><span class="o">,</span> <span class="no">bottom</span><span class="o">,</span> <span class="no">left</span><span class="o">,</span> <span class="no">center</span><span class="p">)</span>
  1443. <span class="c1">// Nope</span>
  1444. <span class="na">$css-positions</span><span class="o">:</span> <span class="p">(</span><span class="no">top</span><span class="o">,</span> <span class="no">right</span><span class="o">,</span> <span class="no">bottom</span><span class="o">,</span> <span class="no">left</span><span class="o">,</span> <span class="no">center</span><span class="p">)</span></code></pre></div>
  1445. </div>
  1446. </div>
  1447. <h6 id="further-reading-14">Further reading</h6>
  1448. <h2 id="namespace">Namespace</h2>
  1449. <p>If you intend to distribute your Sass code, in the case of a library, a framework, a grid system or whatever, you might want to consider namespacing all your variables, functions, mixins and placeholders so it does not conflict with anyone else’s code.</p>
  1450. <p>For instance, if you work on a <em>Sassy Unicorn</em> project that is meant to be used by developers all over the world (who wouldn’t, right?), you could consider using <code>su-</code> as a namespace. It is specific enough to prevent any naming collisions and short enough not to be a pain to write.</p>
  1451. <div class="code-block">
  1452. <div class="code-block__wrapper" data-syntax="scss">
  1453. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="nv">$su-configuration</span><span class="o">:</span> <span class="p">(</span> <span class="o">...</span> <span class="p">);</span>
  1454. <span class="k">@function</span> <span class="nt">su-rainbow</span><span class="o">(</span><span class="err">$</span><span class="nt">unicorn</span><span class="o">)</span> <span class="p">{</span>
  1455. <span class="c1">// ...</span>
  1456. <span class="p">}</span></code></pre></div>
  1457. </div>
  1458. <div class="code-block__wrapper" data-syntax="sass">
  1459. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="na">$su-configuration</span><span class="o">:</span> <span class="p">(</span> <span class="o">...</span> <span class="p">)</span>
  1460. <span class="k">@function</span> <span class="nt">su-rainbow</span><span class="o">(</span><span class="err">$</span><span class="nt">unicorn</span><span class="o">)</span>
  1461. <span class="c1">// ...</span></code></pre></div>
  1462. </div>
  1463. </div>
  1464. <div class="note">
  1465. <p>Note that automatic namespacing is definitely a design goal for the upcoming <code>@import</code> revamp from Sass 4.0. As that comes closer to fruition, it will become less and less useful to do manual namespacing; eventually, manually-namespaced libraries may actually be harder to use.</p>
  1466. </div>
  1467. <h6 id="further-reading-15">Further reading</h6>
  1468. <p>CSS is a tricky language, full of hacks and oddities. Because of this, it should be heavily commented, especially if you or someone else intend to read and update the code 6 months or 1 year from now. Don’t let you or anybody else be in the position of <em>I-didn’t-write-this-oh-my-god-why</em>.</p>
  1469. <p>As simple as CSS can get, there is still a lot of room for comments. These could be explaining:</p>
  1470. <ul>
  1471. <li>the structure and/or role of a file;</li>
  1472. <li>the goal of a ruleset;</li>
  1473. <li>the idea behind a magic number;</li>
  1474. <li>the reason for a CSS declaration;</li>
  1475. <li>the order of CSS declarations;</li>
  1476. <li>the thought process behind a way of doing things.</li>
  1477. </ul>
  1478. <p>And I probably forgot a lot of other various reasons as well. Commenting takes very little time when done seamlessly along with the code so do it at the right time. Coming back at a piece of code to comment it is not only completely unrealistic but also extremely annoying.</p>
  1479. <p>Ideally, <em>any</em> CSS ruleset should be preceded by a C-style comment explaining the point of the CSS block. This comment also hosts numbered explanations regarding specific parts of the ruleset. For instance:</p>
  1480. <div class="code-block">
  1481. <div class="code-block__wrapper" data-syntax="scss">
  1482. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="cm">/**</span>
  1483. <span class="cm"> * Helper class to truncate and add ellipsis to a string too long for it to fit</span>
  1484. <span class="cm"> * on a single line.</span>
  1485. <span class="cm"> * 1. Prevent content from wrapping, forcing it on a single line.</span>
  1486. <span class="cm"> * 2. Add ellipsis at the end of the line.</span>
  1487. <span class="cm"> */</span>
  1488. <span class="nc">.ellipsis</span> <span class="p">{</span>
  1489. <span class="na">white-space</span><span class="o">:</span> <span class="no">nowrap</span><span class="p">;</span> <span class="cm">/* 1 */</span>
  1490. <span class="na">text-overflow</span><span class="o">:</span> <span class="n">ellipsis</span><span class="p">;</span> <span class="cm">/* 2 */</span>
  1491. <span class="na">overflow</span><span class="o">:</span> <span class="no">hidden</span><span class="p">;</span>
  1492. <span class="p">}</span></code></pre></div>
  1493. </div>
  1494. <div class="code-block__wrapper" data-syntax="sass">
  1495. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="cm">/**</span>
  1496. <span class="cm">* Helper class to truncate and add ellipsis to a string too long for it to fit</span>
  1497. <span class="cm">* on a single line.</span>
  1498. <span class="cm">* 1. Prevent content from wrapping, forcing it on a single line.</span>
  1499. <span class="cm">* 2. Add ellipsis at the end of the line.</span>
  1500. <span class="cm">*/</span>
  1501. <span class="nc">.ellipsis</span>
  1502. <span class="na">white-space</span><span class="o">:</span> <span class="no">nowrap</span> <span class="cm">/* 1 </span><span class="c">*/</span>
  1503. <span class="na">text-overflow</span><span class="o">:</span> <span class="n">ellipsis</span> <span class="cm">/* 2 </span><span class="c">*/</span>
  1504. <span class="na">overflow</span><span class="o">:</span> <span class="no">hidden</span></code></pre></div>
  1505. </div>
  1506. </div>
  1507. <p>Basically everything that is not obvious at first glance should be commented. There is no such thing as too much documentation. Remember that you cannot <em>comment too much</em>, so get on fire and write comments for everything that is worth it.</p>
  1508. <p>When commenting a Sass-specific section, use Sass inline comments instead of a C-style block. This makes the comment invisible in the output, even in expanded mode during development.</p>
  1509. <div class="code-block">
  1510. <div class="code-block__wrapper" data-syntax="scss">
  1511. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Add current module to the list of imported modules.</span>
  1512. <span class="c1">// `!global` flag is required so it actually updates the global variable.</span>
  1513. <span class="nv">$imported-modules</span><span class="o">:</span> <span class="nf">append</span><span class="p">(</span><span class="nv">$imported-modules</span><span class="o">,</span> <span class="nv">$module</span><span class="p">)</span> <span class="nv">!global</span><span class="p">;</span></code></pre></div>
  1514. </div>
  1515. <div class="code-block__wrapper" data-syntax="sass">
  1516. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Add current module to the list of imported modules.</span>
  1517. <span class="c1">// `!global` flag is required so it actually updates the global variable.</span>
  1518. <span class="na">$imported-modules</span><span class="o">:</span> <span class="nf">append</span><span class="p">(</span><span class="nv">$imported-modules</span><span class="o">,</span> <span class="nv">$module</span><span class="p">)</span> <span class="nv">!global</span></code></pre></div>
  1519. </div>
  1520. </div>
  1521. <h6 id="further-reading-16">Further reading</h6>
  1522. <h2 id="documentation">Documentation</h2>
  1523. <p>Every variable, function, mixin and placeholder that is intended to be reused all over the codebase should be documented as part of the global API using <a href="http://sassdoc.com">SassDoc</a>.</p>
  1524. <div class="code-block">
  1525. <div class="code-block__wrapper" data-syntax="scss">
  1526. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">/// Vertical rhythm baseline used all over the code base.</span>
  1527. <span class="c1">/// @type Length</span>
  1528. <span class="nv">$vertical-rhythm-baseline</span><span class="o">:</span> <span class="mi">1</span><span class="mf">.5</span><span class="kt">rem</span><span class="p">;</span></code></pre></div>
  1529. </div>
  1530. <div class="code-block__wrapper" data-syntax="sass">
  1531. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">/// Vertical rhythm baseline used all over the code base.</span>
  1532. <span class="c1">/// @type Length</span>
  1533. <span class="na">$vertical-rhythm-baseline</span><span class="o">:</span> <span class="mi">1</span><span class="mf">.5</span><span class="kt">rem</span></code></pre></div>
  1534. </div>
  1535. </div>
  1536. <div class="note">
  1537. <p>Three slashes (<code>/</code>) required.</p>
  1538. </div>
  1539. <p>SassDoc has two major roles:</p>
  1540. <ul>
  1541. <li>forcing standardized comments using an annotation-based system for everything that is part of a public or private API;</li>
  1542. <li>being able to generate an HTML version of the API documentation by using any of the SassDoc endpoints (CLI tool, Grunt, Gulp, Broccoli, Node…).</li>
  1543. </ul>
  1544. <figure role="group">
  1545. <img alt="Documentation generated by SassDoc&#10;" sizes="100vw" srcset="http://sass-guidelin.es/assets/images/sassdoc-preview_small.png 540w,&#10; http://sass-guidelin.es/assets/images/sassdoc-preview_medium.png 900w,&#10; http://sass-guidelin.es/assets/images/sassdoc-preview_large.png 1200w,&#10; http://sass-guidelin.es/assets/images/sassdoc-preview_huge.png 1590w"/>
  1546. <figcaption><p>Documentation generated by SassDoc</p>
  1547. </figcaption>
  1548. </figure>
  1549. <p>Here is an example of a mixin extensively documented with SassDoc:</p>
  1550. <div class="code-block">
  1551. <div class="code-block__wrapper" data-syntax="scss">
  1552. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">/// Mixin helping defining both `width` and `height` simultaneously.</span>
  1553. <span class="c1">///</span>
  1554. <span class="c1">/// @author Hugo Giraudel</span>
  1555. <span class="c1">///</span>
  1556. <span class="c1">/// @access public</span>
  1557. <span class="c1">///</span>
  1558. <span class="c1">/// @param {Length} $width - Element’s `width`</span>
  1559. <span class="c1">/// @param {Length} $height ($width) - Element’s `height`</span>
  1560. <span class="c1">///</span>
  1561. <span class="c1">/// @example scss - Usage</span>
  1562. <span class="c1">/// .foo {</span>
  1563. <span class="c1">/// @include size(10em);</span>
  1564. <span class="c1">/// }</span>
  1565. <span class="c1">///</span>
  1566. <span class="c1">/// .bar {</span>
  1567. <span class="c1">/// @include size(100%, 10em);</span>
  1568. <span class="c1">/// }</span>
  1569. <span class="c1">///</span>
  1570. <span class="c1">/// @example css - CSS output</span>
  1571. <span class="c1">/// .foo {</span>
  1572. <span class="c1">/// width: 10em;</span>
  1573. <span class="c1">/// height: 10em;</span>
  1574. <span class="c1">/// }</span>
  1575. <span class="c1">///</span>
  1576. <span class="c1">/// .bar {</span>
  1577. <span class="c1">/// width: 100%;</span>
  1578. <span class="c1">/// height: 10em;</span>
  1579. <span class="c1">/// }</span>
  1580. <span class="k">@mixin</span><span class="nf"> size</span><span class="p">(</span><span class="nv">$width</span><span class="o">,</span> <span class="nv">$height</span><span class="o">:</span> <span class="nv">$width</span><span class="p">)</span> <span class="p">{</span>
  1581. <span class="na">width</span><span class="o">:</span> <span class="nv">$width</span><span class="p">;</span>
  1582. <span class="na">height</span><span class="o">:</span> <span class="nv">$height</span><span class="p">;</span>
  1583. <span class="p">}</span></code></pre></div>
  1584. </div>
  1585. <div class="code-block__wrapper" data-syntax="sass">
  1586. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">/// Mixin helping defining both `width` and `height` simultaneously.</span>
  1587. <span class="c1">///</span>
  1588. <span class="c1">/// @author Hugo Giraudel</span>
  1589. <span class="c1">///</span>
  1590. <span class="c1">/// @access public</span>
  1591. <span class="c1">///</span>
  1592. <span class="c1">/// @param {Length} $width - Element’s `width`</span>
  1593. <span class="c1">/// @param {Length} $height ($width) - Element’s `height`</span>
  1594. <span class="c1">///</span>
  1595. <span class="c1">/// @example scss - Usage</span>
  1596. <span class="c1">/// .foo</span>
  1597. <span class="c1">/// +size(10em)</span>
  1598. <span class="c1">///</span>
  1599. <span class="c1">/// .bar</span>
  1600. <span class="c1">/// +size(100%, 10em)</span>
  1601. <span class="c1">///</span>
  1602. <span class="c1">/// @example css - CSS output</span>
  1603. <span class="c1">/// .foo {</span>
  1604. <span class="c1">/// width: 10em;</span>
  1605. <span class="c1">/// height: 10em;</span>
  1606. <span class="c1">/// }</span>
  1607. <span class="c1">///</span>
  1608. <span class="c1">/// .bar {</span>
  1609. <span class="c1">/// width: 100%;</span>
  1610. <span class="c1">/// height: 10em;</span>
  1611. <span class="c1">/// }</span>
  1612. <span class="nf">=size</span><span class="p">(</span><span class="nv">$width</span><span class="o">,</span> <span class="nv">$height</span><span class="o">:</span> <span class="nv">$width</span><span class="p">)</span>
  1613. <span class="na">width</span><span class="o">:</span> <span class="nv">$width</span>
  1614. <span class="na">height</span><span class="o">:</span> <span class="nv">$height</span></code></pre></div>
  1615. </div>
  1616. </div>
  1617. <h6 id="further-reading-17">Further reading</h6>
  1618. <h1 id="architecture">Architecture</h1>
  1619. <p>Architecting a CSS project is probably one of the most difficult things you will have to do in a project’s life. Keeping the architecture consistent and meaningful is even harder.</p>
  1620. <p>Fortunately, one of the main benefits of using a CSS preprocessor is having the ability to split the codebase over several files without impacting performance (like the <code>@import</code> CSS directive would do). Thanks to Sass’s overload of the <code>@import</code> directive, it is perfectly safe (and actually recommended) to use as many files as necessary in development, all compiled into a single stylesheet when going to production.</p>
  1621. <p>On top of that, I cannot stress enough the need for folders, even on small scale projects. At home, you don’t drop every sheet of paper into the same box. You use folders; one for the house/flat, one for the bank, one for bills, and so on. There is no reason to do otherwise when structuring a CSS project. Split the codebase into meaningful separated folders so it is easy to find stuff later when you have to come back to the code.</p>
  1622. <p>There are a lot of popular architectures for CSS projects: <a href="http://oocss.org/">OOCSS</a>, <a href="http://bradfrost.com/blog/post/atomic-web-design/">Atomic Design</a>, <a href="http://getbootstrap.com/">Bootstrap</a>-like, <a href="http://foundation.zurb.com/">Foundation</a>-like… They all have their merits, pros and cons.</p>
  1623. <p>I, myself, use an approach that happens to be quite similar to <a href="https://smacss.com/">SMACSS</a> from <a href="http://snook.ca/">Jonathan Snook</a>, which focuses on keeping things simple and obvious.</p>
  1624. <div class="note">
  1625. <p>I have learnt that architecture is most of the time very specific to the project. Feel free to discard completely or adapt the proposed solution so that you deal with a system that suits your needs.</p>
  1626. </div>
  1627. <h6 id="further-reading-18">Further reading</h6>
  1628. <h2 id="components">Components</h2>
  1629. <p>There is a major difference between making it <em>work</em>, and making it <em>good</em>. Again, CSS is quite a messy language <sup>[citation needed]</sup>. The less CSS we have, the merrier. We don’t want to deal with megabytes of CSS code. To keep stylesheets short and efficient—and this will not be any surprise to you—it is usually a good idea to think of an interface as a collection of components.</p>
  1630. <p>Components can be anything, as long as they:</p>
  1631. <ul>
  1632. <li>do one thing and one thing only;</li>
  1633. <li>are re-usable and re-used across the project;</li>
  1634. <li>are independent.</li>
  1635. </ul>
  1636. <p>For instance, a search form should be treated as a component. It should be reusable, at different positions, on different pages, in various situations. It should not depend on its position in the DOM (footer, sidebar, main content…).</p>
  1637. <p>Most of any interface can be thought of as little components and I highly recommend you stick to this paradigm. This will not only shorten the amount of CSS needed for the whole project, but also happens to be much easier to maintain than a chaotic mess where everything is flustered.</p>
  1638. <h2 id="the-7-1-pattern">The 7-1 pattern</h2>
  1639. <p>Back to architecture, shall we? I usually go with what I call the <em>7-1 pattern</em>: 7 folders, 1 file. Basically, you have all your partials stuffed into 7 different folders, and a single file at the root level (usually named <code>main.scss</code>) which imports them all to be compiled into a CSS stylesheet.</p>
  1640. <ul>
  1641. <li><code>base/</code></li>
  1642. <li><code>components/</code></li>
  1643. <li><code>layout/</code></li>
  1644. <li><code>pages/</code></li>
  1645. <li><code>themes/</code></li>
  1646. <li><code>utils/</code></li>
  1647. <li><code>vendors/</code></li>
  1648. </ul>
  1649. <p>And of course:</p>
  1650. <figure role="group">
  1651. <img alt="Wallpaper by Julien He&#10;" sizes="100vw" srcset="http://sass-guidelin.es/assets/images/sass-wallpaper_small.jpg 540w,&#10; http://sass-guidelin.es/assets/images/sass-wallpaper_medium.jpg 900w,&#10; http://sass-guidelin.es/assets/images/sass-wallpaper_large.jpg 1200w,&#10; http://sass-guidelin.es/assets/images/sass-wallpaper_huge.jpg 1590w"/>
  1652. <figcaption><p>Wallpaper by <a href="https://twitter.com/julien_he">Julien He</a></p>
  1653. </figcaption>
  1654. </figure>
  1655. <p>Ideally, we can come up with something like this:</p>
  1656. <div class="highlight"><pre><code>
  1657. sass/
  1658. |
  1659. |– base/
  1660. | |– _reset.scss # Reset/normalize
  1661. | |– _typography.scss # Typography rules
  1662. | ... # Etc…
  1663. |
  1664. |– components/
  1665. | |– _buttons.scss # Buttons
  1666. | |– _carousel.scss # Carousel
  1667. | |– _cover.scss # Cover
  1668. | |– _dropdown.scss # Dropdown
  1669. | ... # Etc…
  1670. |
  1671. |– layout/
  1672. | |– _navigation.scss # Navigation
  1673. | |– _grid.scss # Grid system
  1674. | |– _header.scss # Header
  1675. | |– _footer.scss # Footer
  1676. | |– _sidebar.scss # Sidebar
  1677. | |– _forms.scss # Forms
  1678. | ... # Etc…
  1679. |
  1680. |– pages/
  1681. | |– _home.scss # Home specific styles
  1682. | |– _contact.scss # Contact specific styles
  1683. | ... # Etc…
  1684. |
  1685. |– themes/
  1686. | |– _theme.scss # Default theme
  1687. | |– _admin.scss # Admin theme
  1688. | ... # Etc…
  1689. |
  1690. |– utils/
  1691. | |– _variables.scss # Sass Variables
  1692. | |– _functions.scss # Sass Functions
  1693. | |– _mixins.scss # Sass Mixins
  1694. | |– _helpers.scss # Class &amp; placeholders helpers
  1695. |
  1696. |– vendors/
  1697. | |– _bootstrap.scss # Bootstrap
  1698. | |– _jquery-ui.scss # jQuery UI
  1699. | ... # Etc…
  1700. |
  1701. |
  1702. `– main.scss # Main Sass file
  1703. </code></pre></div>
  1704. <div class="note">
  1705. <p>Files follow the same naming conventions described above: they are hyphen-delimited.</p>
  1706. </div>
  1707. <h3 id="base-folder">Base folder</h3>
  1708. <p>The <code>base/</code> folder holds what we might call the boilerplate code for the project. In there, you might find the reset file, some typographic rules, and probably a stylesheet (that I’m used to calling <code>_base.scss</code>), defining some standard styles for commonly used HTML elements.</p>
  1709. <ul>
  1710. <li><code>_base.scss</code></li>
  1711. <li><code>_reset.scss</code></li>
  1712. <li><code>_typography.scss</code></li>
  1713. </ul>
  1714. <h3 id="layout-folder">Layout folder</h3>
  1715. <p>The <code>layout/</code> folder contains everything that takes part in laying out the site or application. This folder could have stylesheets for the main parts of the site (header, footer, navigation, sidebar…), the grid system or even CSS styles for all the forms.</p>
  1716. <ul>
  1717. <li><code>_grid.scss</code></li>
  1718. <li><code>_header.scss</code></li>
  1719. <li><code>_footer.scss</code></li>
  1720. <li><code>_sidebar.scss</code></li>
  1721. <li><code>_forms.scss</code></li>
  1722. <li><code>_navigation.scss</code></li>
  1723. </ul>
  1724. <div class="note">
  1725. <p>The <code>layout/</code> folder might also be called <code>partials/</code>, depending on what you prefer.</p>
  1726. </div>
  1727. <h3 id="components-folder">Components folder</h3>
  1728. <p>For smaller components, there is the <code>components/</code> folder. While <code>layout/</code> is <em>macro</em> (defining the global wireframe), <code>components/</code> is more focused on widgets. It contains all kind of specific modules like a slider, a loader, a widget, and basically anything along those lines. There are usually a lot of files in <code>components/</code> since the whole site/application should be mostly composed of tiny modules.</p>
  1729. <ul>
  1730. <li><code>_media.scss</code></li>
  1731. <li><code>_carousel.scss</code></li>
  1732. <li><code>_thumbnails.scss</code></li>
  1733. </ul>
  1734. <div class="note">
  1735. <p>The <code>components/</code> folder might also be called <code>modules/</code>, depending on what you prefer.</p>
  1736. </div>
  1737. <h3 id="pages-folder">Pages folder</h3>
  1738. <p>If you have page-specific styles, it is better to put them in a <code>pages/</code> folder, in a file named after the page. For instance, it’s not uncommon to have very specific styles for the home page hence the need for a <code>_home.scss</code> file in <code>pages/</code>.</p>
  1739. <div class="note">
  1740. <p>Depending on your deployment process, these files could be called on their own to avoid merging them with the others in the resulting stylesheet. It is really up to you.</p>
  1741. </div>
  1742. <h3 id="themes-folder">Themes folder</h3>
  1743. <p>On large sites and applications, it is not unusual to have different themes. There are certainly different ways of dealing with themes but I personally like having them all in a <code>themes/</code> folder.</p>
  1744. <div class="note">
  1745. <p>This is very project-specific and is likely to be non-existent on many projects.</p>
  1746. </div>
  1747. <h3 id="utils-folder">Utils folder</h3>
  1748. <p>The <code>utils/</code> folder gathers all Sass tools and helpers used across the project. Every global variable, function, mixin and placeholder should be put in here.</p>
  1749. <p>The rule of thumb for this folder is that it should not output a single line of CSS when compiled on its own. These are nothing but Sass helpers.</p>
  1750. <ul>
  1751. <li><code>_variables.scss</code></li>
  1752. <li><code>_mixins.scss</code></li>
  1753. <li><code>_functions.scss</code></li>
  1754. <li><code>_placeholders.scss</code> (frequently named <code>_helpers.scss</code>)</li>
  1755. </ul>
  1756. <div class="note">
  1757. <p>The <code>utils/</code> folder might also be called <code>helpers/</code>, <code>sass-helpers/</code> or <code>sass-utils/</code>, depending on what you prefer.</p>
  1758. </div>
  1759. <h3 id="vendors-folder">Vendors folder</h3>
  1760. <p>And last but not least, most projects will have a <code>vendors/</code> folder containing all the CSS files from external libraries and frameworks – Normalize, Bootstrap, jQueryUI, FancyCarouselSliderjQueryPowered, and so on. Putting those aside in the same folder is a good way to say “Hey, this is not from me, not my code, not my responsibility”.</p>
  1761. <ul>
  1762. <li><code>_normalize.scss</code></li>
  1763. <li><code>_bootstrap.scss</code></li>
  1764. <li><code>_jquery-ui.scss</code></li>
  1765. <li><code>_select2.scss</code></li>
  1766. </ul>
  1767. <p>If you have to override a section of any vendor, I recommend you have an 8th folder called <code>vendors-extensions/</code> in which you may have files named exactly after the vendors they overwrite.</p>
  1768. <p>For instance, <code>vendors-extensions/_bootstrap.scss</code> is a file containing all CSS rules intended to re-declare some of Bootstrap’s default CSS. This is to avoid editing the vendor files themselves, which is generally not a good idea.</p>
  1769. <h3 id="main-file">Main file</h3>
  1770. <p>The main file (usually labelled <code>main.scss</code>) should be the only Sass file from the whole code base not to begin with an underscore. This file should not contain anything but <code>@import</code> and comments.</p>
  1771. <p>Files should be imported according to the folder they live in, one after the other in the following order:</p>
  1772. <ol>
  1773. <li><code>vendors/</code></li>
  1774. <li><code>utils/</code></li>
  1775. <li><code>base/</code></li>
  1776. <li><code>layout/</code></li>
  1777. <li><code>components/</code></li>
  1778. <li><code>pages/</code></li>
  1779. <li><code>themes/</code></li>
  1780. </ol>
  1781. <p>In order to preserve readability, the main file should respect these guidelines:</p>
  1782. <ul>
  1783. <li>one file per <code>@import</code>;</li>
  1784. <li>one <code>@import</code> per line;</li>
  1785. <li>no new line between two imports from the same folder;</li>
  1786. <li>a new line after the last import from a folder;</li>
  1787. <li>file extensions and leading underscores omitted.</li>
  1788. </ul>
  1789. <div class="code-block">
  1790. <div class="code-block__wrapper" data-syntax="scss">
  1791. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="k">@import</span> <span class="s1">'</span><span class="s2">vendors/bootstrap'</span><span class="p">;</span>
  1792. <span class="k">@import</span> <span class="s1">'</span><span class="s2">vendors/jquery-ui'</span><span class="p">;</span>
  1793. <span class="k">@import</span> <span class="s1">'</span><span class="s2">utils/variables'</span><span class="p">;</span>
  1794. <span class="k">@import</span> <span class="s1">'</span><span class="s2">utils/functions'</span><span class="p">;</span>
  1795. <span class="k">@import</span> <span class="s1">'</span><span class="s2">utils/mixins'</span><span class="p">;</span>
  1796. <span class="k">@import</span> <span class="s1">'</span><span class="s2">utils/placeholders'</span><span class="p">;</span>
  1797. <span class="k">@import</span> <span class="s1">'</span><span class="s2">base/reset'</span><span class="p">;</span>
  1798. <span class="k">@import</span> <span class="s1">'</span><span class="s2">base/typography'</span><span class="p">;</span>
  1799. <span class="k">@import</span> <span class="s1">'</span><span class="s2">layout/navigation'</span><span class="p">;</span>
  1800. <span class="k">@import</span> <span class="s1">'</span><span class="s2">layout/grid'</span><span class="p">;</span>
  1801. <span class="k">@import</span> <span class="s1">'</span><span class="s2">layout/header'</span><span class="p">;</span>
  1802. <span class="k">@import</span> <span class="s1">'</span><span class="s2">layout/footer'</span><span class="p">;</span>
  1803. <span class="k">@import</span> <span class="s1">'</span><span class="s2">layout/sidebar'</span><span class="p">;</span>
  1804. <span class="k">@import</span> <span class="s1">'</span><span class="s2">layout/forms'</span><span class="p">;</span>
  1805. <span class="k">@import</span> <span class="s1">'</span><span class="s2">components/buttons'</span><span class="p">;</span>
  1806. <span class="k">@import</span> <span class="s1">'</span><span class="s2">components/carousel'</span><span class="p">;</span>
  1807. <span class="k">@import</span> <span class="s1">'</span><span class="s2">components/cover'</span><span class="p">;</span>
  1808. <span class="k">@import</span> <span class="s1">'</span><span class="s2">components/dropdown'</span><span class="p">;</span>
  1809. <span class="k">@import</span> <span class="s1">'</span><span class="s2">pages/home'</span><span class="p">;</span>
  1810. <span class="k">@import</span> <span class="s1">'</span><span class="s2">pages/contact'</span><span class="p">;</span>
  1811. <span class="k">@import</span> <span class="s1">'</span><span class="s2">themes/theme'</span><span class="p">;</span>
  1812. <span class="k">@import</span> <span class="s1">'</span><span class="s2">themes/admin'</span><span class="p">;</span></code></pre></div>
  1813. </div>
  1814. <div class="code-block__wrapper" data-syntax="sass">
  1815. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="k">@import</span> <span class="s">vendors/bootstrap</span>
  1816. <span class="k">@import</span> <span class="s">vendors/jquery-ui</span>
  1817. <span class="k">@import</span> <span class="s">utils/variables</span>
  1818. <span class="k">@import</span> <span class="s">utils/functions</span>
  1819. <span class="k">@import</span> <span class="s">utils/mixins</span>
  1820. <span class="k">@import</span> <span class="s">utils/placeholders</span>
  1821. <span class="k">@import</span> <span class="s">base/reset</span>
  1822. <span class="k">@import</span> <span class="s">base/typography</span>
  1823. <span class="k">@import</span> <span class="s">layout/navigation</span>
  1824. <span class="k">@import</span> <span class="s">layout/grid</span>
  1825. <span class="k">@import</span> <span class="s">layout/header</span>
  1826. <span class="k">@import</span> <span class="s">layout/footer</span>
  1827. <span class="k">@import</span> <span class="s">layout/sidebar</span>
  1828. <span class="k">@import</span> <span class="s">layout/forms</span>
  1829. <span class="k">@import</span> <span class="s">components/buttons</span>
  1830. <span class="k">@import</span> <span class="s">components/carousel</span>
  1831. <span class="k">@import</span> <span class="s">components/cover</span>
  1832. <span class="k">@import</span> <span class="s">components/dropdown</span>
  1833. <span class="k">@import</span> <span class="s">pages/home</span>
  1834. <span class="k">@import</span> <span class="s">pages/contact</span>
  1835. <span class="k">@import</span> <span class="s">themes/theme</span>
  1836. <span class="k">@import</span> <span class="s">themes/admin</span></code></pre></div>
  1837. </div>
  1838. </div>
  1839. <p>There is another way of importing partials that I deem valid as well. On the bright side, it makes the file more readable. On the other hand, it makes updating it slightly more painful. Anyway, I’ll let you decide which is best, it does not matter much. For this way of doing, the main file should respect these guidelines:</p>
  1840. <ul>
  1841. <li>one <code>@import</code> per folder;</li>
  1842. <li>a linebreak after <code>@import</code>;</li>
  1843. <li>each file on its own line;</li>
  1844. <li>a new line after the last import from a folder;</li>
  1845. <li>file extensions and leading underscores omitted.</li>
  1846. </ul>
  1847. <div class="code-block">
  1848. <div class="code-block__wrapper" data-syntax="scss">
  1849. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="k">@import</span>
  1850. <span class="s1">'</span><span class="s2">vendors/bootstrap'</span><span class="o">,</span>
  1851. <span class="s1">'</span><span class="s2">vendors/jquery-ui'</span><span class="p">;</span>
  1852. <span class="k">@import</span>
  1853. <span class="s1">'</span><span class="s2">utils/variables'</span><span class="o">,</span>
  1854. <span class="s1">'</span><span class="s2">utils/functions'</span><span class="o">,</span>
  1855. <span class="s1">'</span><span class="s2">utils/mixins'</span><span class="o">,</span>
  1856. <span class="s1">'</span><span class="s2">utils/placeholders'</span><span class="p">;</span>
  1857. <span class="k">@import</span>
  1858. <span class="s1">'</span><span class="s2">base/reset'</span><span class="o">,</span>
  1859. <span class="s1">'</span><span class="s2">base/typography'</span><span class="p">;</span>
  1860. <span class="k">@import</span>
  1861. <span class="s1">'</span><span class="s2">layout/navigation'</span><span class="o">,</span>
  1862. <span class="s1">'</span><span class="s2">layout/grid'</span><span class="o">,</span>
  1863. <span class="s1">'</span><span class="s2">layout/header'</span><span class="o">,</span>
  1864. <span class="s1">'</span><span class="s2">layout/footer'</span><span class="o">,</span>
  1865. <span class="s1">'</span><span class="s2">layout/sidebar'</span><span class="o">,</span>
  1866. <span class="s1">'</span><span class="s2">layout/forms'</span><span class="p">;</span>
  1867. <span class="k">@import</span>
  1868. <span class="s1">'</span><span class="s2">components/buttons'</span><span class="o">,</span>
  1869. <span class="s1">'</span><span class="s2">components/carousel'</span><span class="o">,</span>
  1870. <span class="s1">'</span><span class="s2">components/cover'</span><span class="o">,</span>
  1871. <span class="s1">'</span><span class="s2">components/dropdown'</span><span class="p">;</span>
  1872. <span class="k">@import</span>
  1873. <span class="s1">'</span><span class="s2">pages/home'</span><span class="o">,</span>
  1874. <span class="s1">'</span><span class="s2">pages/contact'</span><span class="p">;</span>
  1875. <span class="k">@import</span>
  1876. <span class="s1">'</span><span class="s2">themes/theme'</span><span class="o">,</span>
  1877. <span class="s1">'</span><span class="s2">themes/admin'</span><span class="p">;</span></code></pre></div>
  1878. </div>
  1879. <div class="code-block__wrapper" data-syntax="sass">
  1880. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="k">@import</span>
  1881. <span class="nt">vendors</span><span class="o">/</span><span class="nt">bootstrap</span><span class="o">,</span>
  1882. <span class="nt">vendors</span><span class="o">/</span><span class="nt">jquery-ui</span>
  1883. <span class="k">@import</span>
  1884. <span class="nt">utils</span><span class="o">/</span><span class="nt">variables</span><span class="o">,</span>
  1885. <span class="nt">utils</span><span class="o">/</span><span class="nt">functions</span><span class="o">,</span>
  1886. <span class="nt">utils</span><span class="o">/</span><span class="nt">mixins</span><span class="o">,</span>
  1887. <span class="nt">utils</span><span class="o">/</span><span class="nt">placeholders</span>
  1888. <span class="k">@import</span>
  1889. <span class="nt">base</span><span class="o">/</span><span class="nt">reset</span><span class="o">,</span>
  1890. <span class="nt">base</span><span class="o">/</span><span class="nt">typography</span>
  1891. <span class="k">@import</span>
  1892. <span class="nt">layout</span><span class="o">/</span><span class="nt">navigation</span><span class="o">,</span>
  1893. <span class="nt">layout</span><span class="o">/</span><span class="nt">grid</span><span class="o">,</span>
  1894. <span class="nt">layout</span><span class="o">/</span><span class="nt">header</span><span class="o">,</span>
  1895. <span class="nt">layout</span><span class="o">/</span><span class="nt">footer</span><span class="o">,</span>
  1896. <span class="nt">layout</span><span class="o">/</span><span class="nt">sidebar</span><span class="o">,</span>
  1897. <span class="nt">layout</span><span class="o">/</span><span class="nt">forms</span>
  1898. <span class="k">@import</span>
  1899. <span class="nt">components</span><span class="o">/</span><span class="nt">buttons</span><span class="o">,</span>
  1900. <span class="nt">components</span><span class="o">/</span><span class="nt">carousel</span><span class="o">,</span>
  1901. <span class="nt">components</span><span class="o">/</span><span class="nt">cover</span><span class="o">,</span>
  1902. <span class="nt">components</span><span class="o">/</span><span class="nt">dropdown</span>
  1903. <span class="k">@import</span>
  1904. <span class="nt">pages</span><span class="o">/</span><span class="nt">home</span><span class="o">,</span>
  1905. <span class="nt">pages</span><span class="o">/</span><span class="nt">contact</span>
  1906. <span class="k">@import</span>
  1907. <span class="nt">themes</span><span class="o">/</span><span class="nt">theme</span><span class="o">,</span>
  1908. <span class="nt">themes</span><span class="o">/</span><span class="nt">admin</span></code></pre></div>
  1909. </div>
  1910. </div>
  1911. <div class="note">
  1912. <p>In order to not have to import each file manually, there is an extension to Ruby Sass called <a href="https://github.com/chriseppstein/sass-globbing">sass-globbing</a>, making it possible to use glob patterns in Sass <code>@import</code> such as <code>@import "components/*"</code>.</p>
  1913. <p>That being said, I would not recommend it because it imports files following the alphabetical order which is usually not what you want, especially when dealing with a source-order dependent language.</p>
  1914. </div>
  1915. <h2 id="shame-file">Shame file</h2>
  1916. <p>There is an interesting concept that has been made popular by <a href="http://csswizardry.com">Harry Roberts</a>, <a href="http://daverupert.com">Dave Rupert</a> and <a href="http://css-tricks.com">Chris Coyier</a> that consists of putting all the CSS declarations, hacks and things we are not proud of in a <em>shame file</em>. This file, dramatically titled <code>_shame.scss</code>, would be imported after any other file, at the very end of the stylesheet.</p>
  1917. <div class="code-block">
  1918. <div class="code-block__wrapper" data-syntax="scss">
  1919. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="cm">/**</span>
  1920. <span class="cm"> * Nav specificity fix.</span>
  1921. <span class="cm"> *</span>
  1922. <span class="cm"> * Someone used an ID in the header code (`#header a {}`) which trumps the</span>
  1923. <span class="cm"> * nav selectors (`.site-nav a {}`). Use !important to override it until I</span>
  1924. <span class="cm"> * have time to refactor the header stuff.</span>
  1925. <span class="cm"> */</span>
  1926. <span class="nc">.site-nav</span> <span class="nt">a</span> <span class="p">{</span>
  1927. <span class="na">color</span><span class="o">:</span> <span class="mh">#BADA55</span> <span class="nv">!important</span><span class="p">;</span>
  1928. <span class="p">}</span></code></pre></div>
  1929. </div>
  1930. <div class="code-block__wrapper" data-syntax="sass">
  1931. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="cm">/**</span>
  1932. <span class="cm">* Nav specificity fix.</span>
  1933. <span class="cm">*</span>
  1934. <span class="cm">* Someone used an ID in the header code (`#header a {}`) which trumps the</span>
  1935. <span class="cm">* nav selectors (`.site-nav a {}`). Use !important to override it until I</span>
  1936. <span class="cm">* have time to refactor the header stuff.</span>
  1937. <span class="cm">*/</span>
  1938. <span class="nc">.site-nav</span> <span class="nt">a</span>
  1939. <span class="na">color</span><span class="o">:</span> <span class="mh">#BADA55</span> <span class="nv">!important</span></code></pre></div>
  1940. </div>
  1941. </div>
  1942. <h6 id="further-reading-19">Further reading</h6>
  1943. <h1 id="responsive-web-design-and-breakpoints">Responsive Web Design and breakpoints</h1>
  1944. <p>I do not think we still have to introduce Responsive Web Design now that it is everywhere. However you might ask yourself <em>why is there a section about RWD in a Sass styleguide?</em> Actually there are quite a few things that can be done to make working with breakpoints easier, so I thought it would not be such a bad idea to list them here.</p>
  1945. <h2 id="naming-breakpoints">Naming breakpoints</h2>
  1946. <p>I think it is safe to say that media queries should not be tied to specific devices. For instance, this is definitely a bad idea to try targeting iPads or Blackberry phones specifically. Media queries should take care of a range of screen sizes, until the design breaks and the next media query takes over.</p>
  1947. <p>For the same reasons, breakpoints should not be named after devices but something more general. Especially since some phones are now bigger than tablets, some tablets bigger than some tiny screen computers, and so on…</p>
  1948. <div class="code-block">
  1949. <div class="code-block__wrapper" data-syntax="scss">
  1950. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Yep</span>
  1951. <span class="nv">$breakpoints</span><span class="o">:</span> <span class="p">(</span>
  1952. <span class="s1">'</span><span class="s2">medium'</span><span class="o">:</span> <span class="p">(</span><span class="no">min-width</span><span class="o">:</span> <span class="mi">800</span><span class="kt">px</span><span class="p">)</span><span class="o">,</span>
  1953. <span class="s1">'</span><span class="s2">large'</span><span class="o">:</span> <span class="p">(</span><span class="no">min-width</span><span class="o">:</span> <span class="mi">1000</span><span class="kt">px</span><span class="p">)</span><span class="o">,</span>
  1954. <span class="s1">'</span><span class="s2">huge'</span><span class="o">:</span> <span class="p">(</span><span class="no">min-width</span><span class="o">:</span> <span class="mi">1200</span><span class="kt">px</span><span class="p">)</span><span class="o">,</span>
  1955. <span class="p">);</span>
  1956. <span class="c1">// Nope</span>
  1957. <span class="nv">$breakpoints</span><span class="o">:</span> <span class="p">(</span>
  1958. <span class="s1">'</span><span class="s2">tablet'</span><span class="o">:</span> <span class="p">(</span><span class="no">min-width</span><span class="o">:</span> <span class="mi">800</span><span class="kt">px</span><span class="p">)</span><span class="o">,</span>
  1959. <span class="s1">'</span><span class="s2">computer'</span><span class="o">:</span> <span class="p">(</span><span class="no">min-width</span><span class="o">:</span> <span class="mi">1000</span><span class="kt">px</span><span class="p">)</span><span class="o">,</span>
  1960. <span class="s1">'</span><span class="s2">tv'</span><span class="o">:</span> <span class="p">(</span><span class="no">min-width</span><span class="o">:</span> <span class="mi">1200</span><span class="kt">px</span><span class="p">)</span><span class="o">,</span>
  1961. <span class="p">);</span></code></pre></div>
  1962. </div>
  1963. <div class="code-block__wrapper" data-syntax="sass">
  1964. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Yep</span>
  1965. <span class="nv">$breakpoints</span><span class="o">:</span> <span class="p">(</span><span class="s1">'</span><span class="s2">medium'</span><span class="o">:</span> <span class="p">(</span><span class="no">min-width</span><span class="o">:</span> <span class="mi">800</span><span class="kt">px</span><span class="p">)</span><span class="o">,</span> <span class="s1">'</span><span class="s2">large'</span><span class="o">:</span> <span class="p">(</span><span class="no">min-width</span><span class="o">:</span> <span class="mi">1000</span><span class="kt">px</span><span class="p">)</span><span class="o">,</span> <span class="s1">'</span><span class="s2">huge'</span><span class="o">:</span> <span class="p">(</span><span class="no">min-width</span><span class="o">:</span> <span class="mi">1200</span><span class="kt">px</span><span class="p">))</span>
  1966. <span class="c1">// Nope</span>
  1967. <span class="nv">$breakpoints</span><span class="o">:</span> <span class="p">(</span><span class="s1">'</span><span class="s2">tablet'</span><span class="o">:</span> <span class="p">(</span><span class="no">min-width</span><span class="o">:</span> <span class="mi">800</span><span class="kt">px</span><span class="p">)</span><span class="o">,</span> <span class="s1">'</span><span class="s2">computer'</span><span class="o">:</span> <span class="p">(</span><span class="no">min-width</span><span class="o">:</span> <span class="mi">1000</span><span class="kt">px</span><span class="p">)</span><span class="o">,</span> <span class="s1">'</span><span class="s2">tv'</span><span class="o">:</span> <span class="p">(</span><span class="no">min-width</span><span class="o">:</span> <span class="mi">1200</span><span class="kt">px</span><span class="p">))</span></code></pre></div>
  1968. </div>
  1969. </div>
  1970. <p>At this point, any naming convention that makes crystal clear that a design is not intimately tied to a specific device type will do the trick, as long as it gives a sense of magnitude.</p>
  1971. <div class="code-block">
  1972. <div class="code-block__wrapper" data-syntax="scss">
  1973. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="nv">$breakpoints</span><span class="o">:</span> <span class="p">(</span>
  1974. <span class="s1">'</span><span class="s2">seed'</span><span class="o">:</span> <span class="p">(</span><span class="no">min-width</span><span class="o">:</span> <span class="mi">800</span><span class="kt">px</span><span class="p">)</span><span class="o">,</span>
  1975. <span class="s1">'</span><span class="s2">sprout'</span><span class="o">:</span> <span class="p">(</span><span class="no">min-width</span><span class="o">:</span> <span class="mi">1000</span><span class="kt">px</span><span class="p">)</span><span class="o">,</span>
  1976. <span class="s1">'</span><span class="s2">plant'</span><span class="o">:</span> <span class="p">(</span><span class="no">min-width</span><span class="o">:</span> <span class="mi">1200</span><span class="kt">px</span><span class="p">)</span><span class="o">,</span>
  1977. <span class="p">);</span></code></pre></div>
  1978. </div>
  1979. <div class="code-block__wrapper" data-syntax="sass">
  1980. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="nv">$breakpoints</span><span class="o">:</span> <span class="p">(</span><span class="s1">'</span><span class="s2">seed'</span><span class="o">:</span> <span class="p">(</span><span class="no">min-width</span><span class="o">:</span> <span class="mi">800</span><span class="kt">px</span><span class="p">)</span><span class="o">,</span> <span class="s1">'</span><span class="s2">sprout'</span><span class="o">:</span> <span class="p">(</span><span class="no">min-width</span><span class="o">:</span> <span class="mi">1000</span><span class="kt">px</span><span class="p">)</span><span class="o">,</span> <span class="s1">'</span><span class="s2">plant'</span><span class="o">:</span> <span class="p">(</span><span class="no">min-width</span><span class="o">:</span> <span class="mi">1200</span><span class="kt">px</span><span class="p">))</span></code></pre></div>
  1981. </div>
  1982. </div>
  1983. <div class="note">
  1984. <p>The previous examples uses nested maps to define breakpoints, however this really depends on what kind of breakpoint manager you use. You could opt for strings rather than inner maps for more flexibility (e.g. <code>'(min-width: 800px)'</code>).</p>
  1985. </div>
  1986. <h6 id="further-reading-20">Further reading</h6>
  1987. <h2 id="breakpoint-manager">Breakpoint manager</h2>
  1988. <p>Once you have named your breakpoints the way you want, you need a way to use them in actual media queries. There are plenty of ways to do so but I must say I am a big fan of the breakpoint map read by a getter function. This system is both simple and efficient.</p>
  1989. <div class="code-block">
  1990. <div class="code-block__wrapper" data-syntax="scss">
  1991. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">/// Responsive manager.</span>
  1992. <span class="c1">/// @access public</span>
  1993. <span class="c1">/// @param {String} $breakpoint - Breakpoint</span>
  1994. <span class="c1">/// @requires $breakpoints</span>
  1995. <span class="k">@mixin</span><span class="nf"> respond-to</span><span class="p">(</span><span class="nv">$breakpoint</span><span class="p">)</span> <span class="p">{</span>
  1996. <span class="nv">$raw-query</span><span class="o">:</span> <span class="nf">map-get</span><span class="p">(</span><span class="nv">$breakpoints</span><span class="o">,</span> <span class="nv">$breakpoint</span><span class="p">);</span>
  1997. <span class="k">@if</span> <span class="nv">$raw-query</span> <span class="p">{</span>
  1998. <span class="nv">$query</span><span class="o">:</span> <span class="nf">if</span><span class="p">(</span><span class="nf">type-of</span><span class="p">(</span><span class="nv">$raw-query</span><span class="p">)</span> <span class="o">==</span> <span class="s1">'</span><span class="s2">string'</span><span class="o">,</span> <span class="nf">unquote</span><span class="p">(</span><span class="nv">$raw-query</span><span class="p">)</span><span class="o">,</span> <span class="nf">inspect</span><span class="p">(</span><span class="nv">$raw-query</span><span class="p">));</span>
  1999. <span class="k">@media</span> <span class="nn">#</span><span class="p">{</span><span class="err">$</span><span class="nt">query</span><span class="p">}</span> <span class="p">{</span>
  2000. <span class="k">@content</span><span class="o">;</span>
  2001. <span class="p">}</span>
  2002. <span class="p">}</span> <span class="k">@else</span> <span class="p">{</span>
  2003. <span class="k">@error</span> <span class="s1">'</span><span class="s2">No value found for `</span><span class="si">#{</span><span class="nv">$breakpoint</span><span class="si">}</span><span class="s2">`. '</span>
  2004. <span class="o">+</span> <span class="s1">'</span><span class="s2">Please make sure it is defined in `$breakpoints` map.'</span><span class="o">;</span>
  2005. <span class="p">}</span>
  2006. <span class="p">}</span></code></pre></div>
  2007. </div>
  2008. <div class="code-block__wrapper" data-syntax="sass">
  2009. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">/// Responsive manager.</span>
  2010. <span class="c1">/// @access public</span>
  2011. <span class="c1">/// @param {String} $breakpoint - Breakpoint</span>
  2012. <span class="c1">/// @requires $breakpoints</span>
  2013. <span class="nf">=respond-to</span><span class="p">(</span><span class="nv">$breakpoint</span><span class="p">)</span>
  2014. <span class="na">$raw-query</span><span class="o">:</span> <span class="nf">map-get</span><span class="p">(</span><span class="nv">$breakpoints</span><span class="o">,</span> <span class="nv">$breakpoint</span><span class="p">)</span>
  2015. <span class="k">@if</span> <span class="nv">$raw-query</span>
  2016. <span class="nv">$query</span><span class="o">:</span> <span class="nf">if</span><span class="p">(</span><span class="nf">type-of</span><span class="p">(</span><span class="nv">$raw-query</span><span class="p">)</span> <span class="o">==</span> <span class="s1">'</span><span class="s2">string'</span><span class="o">,</span> <span class="nf">unquote</span><span class="p">(</span><span class="nv">$raw-query</span><span class="p">)</span><span class="o">,</span> <span class="nf">inspect</span><span class="p">(</span><span class="nv">$raw-query</span><span class="p">))</span>
  2017. <span class="k">@media</span> <span class="nn">#</span><span class="err">{$</span><span class="nt">query</span><span class="err">}</span>
  2018. <span class="k">@content</span>
  2019. <span class="k">@else</span>
  2020. <span class="k">@error</span> <span class="s1">'</span><span class="s2">No value found for `</span><span class="si">#{</span><span class="nv">$breakpoint</span><span class="si">}</span><span class="s2">`. '</span>
  2021. <span class="o">+</span> <span class="s1">'</span><span class="s2">Please make sure it is defined in `$breakpoints` map.'</span></code></pre></div>
  2022. </div>
  2023. </div>
  2024. <div class="note">
  2025. <p>Obviously, this is a fairly simplistic breakpoint manager. If you need a slightly more permissive one, may I recommend you do not reinvent the wheel and use something that has been proven effective such as <a href="https://github.com/sass-mq/sass-mq">Sass-MQ</a>, <a href="http://breakpoint-sass.com/">Breakpoint</a> or <a href="https://github.com/eduardoboucas/include-media">include-media</a>.</p>
  2026. </div>
  2027. <h6 id="further-reading-21">Further reading</h6>
  2028. <p>Not so long ago, there was quite a hot debate about where media queries should be written: do they belong within selectors (as Sass allows it) or strictly dissociated from them? I have to say I am a fervent defender of the <em>media-queries-within-selectors</em> system, as I think it plays well with the ideas of <em>components</em>.</p>
  2029. <div class="code-block">
  2030. <div class="code-block__wrapper" data-syntax="scss">
  2031. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="nc">.foo</span> <span class="p">{</span>
  2032. <span class="na">color</span><span class="o">:</span> <span class="nb">red</span><span class="p">;</span>
  2033. <span class="k">@include</span><span class="nd"> respond-to</span><span class="p">(</span><span class="s1">'</span><span class="s2">medium'</span><span class="p">)</span> <span class="p">{</span>
  2034. <span class="na">color</span><span class="o">:</span> <span class="nb">blue</span><span class="p">;</span>
  2035. <span class="p">}</span>
  2036. <span class="p">}</span></code></pre></div>
  2037. </div>
  2038. <div class="code-block__wrapper" data-syntax="sass">
  2039. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="nc">.foo</span>
  2040. <span class="na">color</span><span class="o">:</span> <span class="nb">red</span>
  2041. <span class="nd">+respond-to</span><span class="p">(</span><span class="s1">'</span><span class="s2">medium'</span><span class="p">)</span>
  2042. <span class="na">color</span><span class="o">:</span> <span class="nb">blue</span></code></pre></div>
  2043. </div>
  2044. </div>
  2045. <p>Leading to the following CSS output:</p>
  2046. <div>
  2047. <div class="highlight"><pre><code class="language-css" data-lang="css"><span class="nc">.foo</span> <span class="p">{</span>
  2048. <span class="k">color</span><span class="o">:</span> <span class="nb">red</span><span class="p">;</span>
  2049. <span class="p">}</span>
  2050. <span class="k">@media</span> <span class="o">(</span><span class="nt">min-width</span><span class="o">:</span> <span class="nt">800px</span><span class="o">)</span> <span class="p">{</span>
  2051. <span class="nc">.foo</span> <span class="p">{</span>
  2052. <span class="k">color</span><span class="o">:</span> <span class="nb">blue</span><span class="p">;</span>
  2053. <span class="p">}</span>
  2054. <span class="p">}</span></code></pre></div>
  2055. </div>
  2056. <p>You might hear that this convention results in duplicated media queries in the CSS output. That is definitely true. Although, <a href="http://sasscast.tumblr.com/post/38673939456/sass-and-media-queries">tests have been made</a> and the final word is that it doesn’t matter once Gzip (or any equivalent) has done its thing:</p>
  2057. <blockquote>
  2058. <p>… we hashed out whether there were performance implications of combining vs scattering Media Queries and came to the conclusion that the difference, while ugly, is minimal at worst, essentially non-existent at best.<br/>
  2059. — <a href="https://twitter.com/snugug">Sam Richards</a>, regarding <a href="http://breakpoint-sass.com/">Breakpoint</a></p>
  2060. </blockquote>
  2061. <p>Now, if you really are concerned about duplicated media queries, you can still use a tool to merge them such as <a href="https://github.com/aaronjensen/sass-media_query_combiner">this gem</a> however I feel like I have to warn you against possible side-effects of moving CSS code around. You are not without knowing that source order is important.</p>
  2062. <h6 id="further-reading-22">Further reading</h6>
  2063. <h1 id="variables">Variables</h1>
  2064. <p>Variables are the essence of any programming language. They allow us to reuse values without having to copy them over and over again. Most importantly, they make updating a value very easy. No more find and replace or manual crawling.</p>
  2065. <p>However CSS is nothing but a huge basket containing all our eggs. Unlike many languages, there are no real scopes in CSS. Because of this, we have to pay real attention when adding variables at the risk of witnessing conflicts.</p>
  2066. <p>My advice would be to only create variables when it makes sense to do so. Do not initiate new variables for the heck of it, it won’t help. A new variable should be created only when all of the following criteria are met:</p>
  2067. <ul>
  2068. <li>the value is repeated at least twice;</li>
  2069. <li>the value is likely to be updated at least once;</li>
  2070. <li>all occurrences of the value are tied to the variable (i.e. not by coincidence).</li>
  2071. </ul>
  2072. <p>Basically, there is no point declaring a variable that will never be updated or that is only being used at a single place.</p>
  2073. <h2 id="scoping">Scoping</h2>
  2074. <p>Variable scoping in Sass has changed over the years. Until fairly recently, variable declarations within rulesets and other scopes were local by default. However when there was already a global variable with the same name, the local assignment would change the global variable. Since version 3.4, Sass now properly tackles the concept of scopes and create a new local variable instead.</p>
  2075. <p>The docs talk about <em>global variable shadowing</em>. When declaring a variable that already exists on the global scope in an inner scope (selector, function, mixin…), the local variable is said to be <em>shadowing</em> the global one. Basically, it overrides it just for the local scope.</p>
  2076. <p>The following code snippet explains the <em>variable shadowing</em> concept.</p>
  2077. <div class="code-block">
  2078. <div class="code-block__wrapper" data-syntax="scss">
  2079. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Initialize a global variable at root level.</span>
  2080. <span class="nv">$variable</span><span class="o">:</span> <span class="s1">'</span><span class="s2">initial value'</span><span class="p">;</span>
  2081. <span class="c1">// Create a mixin that overrides that global variable.</span>
  2082. <span class="k">@mixin</span><span class="nf"> global-variable-overriding</span> <span class="p">{</span>
  2083. <span class="nv">$variable</span><span class="o">:</span> <span class="s1">'</span><span class="s2">mixin value'</span> <span class="nv">!global</span><span class="p">;</span>
  2084. <span class="p">}</span>
  2085. <span class="na">.local-scope</span><span class="o">::</span><span class="n">before</span> <span class="p">{</span>
  2086. <span class="c1">// Create a local variable that shadows the global one.</span>
  2087. <span class="nv">$variable</span><span class="o">:</span> <span class="s1">'</span><span class="s2">local value'</span><span class="p">;</span>
  2088. <span class="c1">// Include the mixin: it overrides the global variable.</span>
  2089. <span class="k">@include</span><span class="nd"> global-variable-overriding</span><span class="p">;</span>
  2090. <span class="c1">// Print the variable’s value.</span>
  2091. <span class="c1">// It is the **local** one, since it shadows the global one.</span>
  2092. <span class="na">content</span><span class="o">:</span> <span class="nv">$variable</span><span class="p">;</span>
  2093. <span class="p">}</span>
  2094. <span class="c1">// Print the variable in another selector that does no shadowing.</span>
  2095. <span class="c1">// It is the **global** one, as expected.</span>
  2096. <span class="na">.other-local-scope</span><span class="o">::</span><span class="n">before</span> <span class="p">{</span>
  2097. <span class="na">content</span><span class="o">:</span> <span class="nv">$variable</span><span class="p">;</span>
  2098. <span class="p">}</span></code></pre></div>
  2099. </div>
  2100. <div class="code-block__wrapper" data-syntax="sass">
  2101. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Initialize a global variable at root level.</span>
  2102. <span class="nv">$variable</span><span class="o">:</span> <span class="s1">'</span><span class="s2">initial value'</span>
  2103. <span class="c1">// Create a mixin that overrides that global variable.</span>
  2104. <span class="k">@mixin</span><span class="nf"> global-variable-overriding</span>
  2105. <span class="nv">$variable</span><span class="o">:</span> <span class="s1">'</span><span class="s2">mixin value'</span> <span class="nv">!global</span>
  2106. <span class="na">.local-scope</span><span class="o">::</span><span class="n">before</span>
  2107. <span class="c1">// Create a local variable that shadows the global one.</span>
  2108. <span class="nv">$variable</span><span class="o">:</span> <span class="s1">'</span><span class="s2">local value'</span>
  2109. <span class="c1">// Include the mixin: it overrides the global variable.</span>
  2110. <span class="nd">+global-variable-overriding</span>
  2111. <span class="c1">// Print the variable’s value.</span>
  2112. <span class="c1">// It is the **local** one, since it shadows the global one.</span>
  2113. <span class="na">content</span><span class="o">:</span> <span class="nv">$variable</span>
  2114. <span class="c1">// Print the variable in another selector that does no shadowing.</span>
  2115. <span class="c1">// It is the **global** one, as expected.</span>
  2116. <span class="na">.other-local-scope</span><span class="o">::</span><span class="n">before</span>
  2117. <span class="na">content</span><span class="o">:</span> <span class="nv">$variable</span></code></pre></div>
  2118. </div>
  2119. </div>
  2120. <h2 id="default-flag"><code>!default</code> flag</h2>
  2121. <p>When building a library, a framework, a grid system or any piece of Sass that is intended to be distributed and used by external developers, all configuration variables should be defined with the <code>!default</code> flag so they can be overwritten.</p>
  2122. <p>Thanks to this, a developer can define his own <code>$baseline</code> variable <em>before</em> importing your library without seeing his value redefined.</p>
  2123. <div class="code-block">
  2124. <div class="code-block__wrapper" data-syntax="scss">
  2125. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Developer’s own variable</span>
  2126. <span class="nv">$baseline</span><span class="o">:</span> <span class="mi">2</span><span class="kt">em</span><span class="p">;</span>
  2127. <span class="c1">// Your library declaring `$baseline`</span>
  2128. <span class="k">@import</span> <span class="s1">'</span><span class="s2">your-library'</span><span class="p">;</span>
  2129. <span class="c1">// $baseline == 2em;</span></code></pre></div>
  2130. </div>
  2131. <div class="code-block__wrapper" data-syntax="sass">
  2132. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Developer’s own variable</span>
  2133. <span class="nv">$baseline</span><span class="o">:</span> <span class="mi">2</span><span class="kt">em</span>
  2134. <span class="c1">// Your library declaring `$baseline`</span>
  2135. <span class="k">@import</span> <span class="s">your-library</span>
  2136. <span class="c1">// $baseline == 2em</span></code></pre></div>
  2137. </div>
  2138. </div>
  2139. <h2 id="global-flag"><code>!global</code> flag</h2>
  2140. <p>The <code>!global</code> flag should only be used when overriding a global variable from a local scope. When defining a variable at root level, the <code>!global</code> flag should be omitted.</p>
  2141. <div class="code-block">
  2142. <div class="code-block__wrapper" data-syntax="scss">
  2143. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Yep</span>
  2144. <span class="nv">$baseline</span><span class="o">:</span> <span class="mi">2</span><span class="kt">em</span><span class="p">;</span>
  2145. <span class="c1">// Nope</span>
  2146. <span class="nv">$baseline</span><span class="o">:</span> <span class="mi">2</span><span class="kt">em</span> <span class="nv">!global</span><span class="p">;</span></code></pre></div>
  2147. </div>
  2148. <div class="code-block__wrapper" data-syntax="sass">
  2149. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Yep</span>
  2150. <span class="nv">$baseline</span><span class="o">:</span> <span class="mi">2</span><span class="kt">em</span>
  2151. <span class="c1">// Nope</span>
  2152. <span class="nv">$baseline</span><span class="o">:</span> <span class="mi">2</span><span class="kt">em</span> <span class="nv">!global</span></code></pre></div>
  2153. </div>
  2154. </div>
  2155. <h2 id="multiple-variables-or-maps">Multiple variables or maps</h2>
  2156. <p>There are advantages of using maps rather than multiple distinct variables. The main one is the ability to loop over a map, which is not possible with distinct variables.</p>
  2157. <p>Another pro of using a map is the ability to create a little getter function to provide a friendlier API. For instance, consider the following Sass code:</p>
  2158. <div class="code-block">
  2159. <div class="code-block__wrapper" data-syntax="scss">
  2160. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">/// Z-indexes map, gathering all Z layers of the application</span>
  2161. <span class="c1">/// @access private</span>
  2162. <span class="c1">/// @type Map</span>
  2163. <span class="c1">/// @prop {String} key - Layer's name</span>
  2164. <span class="c1">/// @prop {Number} value - Z value mapped to the key</span>
  2165. <span class="nv">$z-indexes</span><span class="o">:</span> <span class="p">(</span>
  2166. <span class="s1">'</span><span class="s2">modal'</span><span class="o">:</span> <span class="mi">5000</span><span class="o">,</span>
  2167. <span class="s1">'</span><span class="s2">dropdown'</span><span class="o">:</span> <span class="mi">4000</span><span class="o">,</span>
  2168. <span class="s1">'</span><span class="s2">default'</span><span class="o">:</span> <span class="mi">1</span><span class="o">,</span>
  2169. <span class="s1">'</span><span class="s2">below'</span><span class="o">:</span> <span class="mi">-1</span><span class="o">,</span>
  2170. <span class="p">);</span>
  2171. <span class="c1">/// Get a z-index value from a layer name</span>
  2172. <span class="c1">/// @access public</span>
  2173. <span class="c1">/// @param {String} $layer - Layer’s name</span>
  2174. <span class="c1">/// @return {Number}</span>
  2175. <span class="c1">/// @require $z-indexes</span>
  2176. <span class="k">@function</span> <span class="nt">z</span><span class="o">(</span><span class="err">$</span><span class="nt">layer</span><span class="o">)</span> <span class="p">{</span>
  2177. <span class="k">@return</span> <span class="nt">map-get</span><span class="o">(</span><span class="err">$</span><span class="nt">z-indexes</span><span class="o">,</span> <span class="err">$</span><span class="nt">layer</span><span class="o">);</span>
  2178. <span class="p">}</span></code></pre></div>
  2179. </div>
  2180. <div class="code-block__wrapper" data-syntax="sass">
  2181. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">/// Z-indexes map, gathering all Z layers of the application</span>
  2182. <span class="c1">/// @access private</span>
  2183. <span class="c1">/// @type Map</span>
  2184. <span class="c1">/// @prop {String} key - Layer’s name</span>
  2185. <span class="c1">/// @prop {Number} value - Z value mapped to the key</span>
  2186. <span class="na">$z-indexes</span><span class="o">:</span> <span class="p">(</span><span class="s1">'</span><span class="s2">modal'</span><span class="o">:</span> <span class="mi">5000</span><span class="o">,</span> <span class="s1">'</span><span class="s2">dropdown'</span><span class="o">:</span> <span class="mi">4000</span><span class="o">,</span> <span class="s1">'</span><span class="s2">default'</span><span class="o">:</span> <span class="mi">1</span><span class="o">,</span> <span class="s1">'</span><span class="s2">below'</span><span class="o">:</span> <span class="mi">-1</span><span class="o">,</span><span class="p">)</span>
  2187. <span class="c1">/// Get a z-index value from a layer name</span>
  2188. <span class="c1">/// @access public</span>
  2189. <span class="c1">/// @param {String} $layer - Layer's name</span>
  2190. <span class="c1">/// @return {Number}</span>
  2191. <span class="c1">/// @require $z-indexes</span>
  2192. <span class="k">@function</span> <span class="nt">z</span><span class="o">(</span><span class="err">$</span><span class="nt">layer</span><span class="o">)</span>
  2193. <span class="k">@return</span> <span class="nt">map-get</span><span class="o">(</span><span class="err">$</span><span class="nt">z-indexes</span><span class="o">,</span> <span class="err">$</span><span class="nt">layer</span><span class="o">)</span></code></pre></div>
  2194. </div>
  2195. </div>
  2196. <h1 id="extend">Extend</h1>
  2197. <p>The <code>@extend</code> directive has to be one of the features that made Sass so popular a couple of years ago. As a reminder, it makes it possible to tell Sass to style an element A exactly as though it also matched selector B. Needless to say this can end up being a valuable ally when writing modular CSS.</p>
  2198. <p>However I feel like I must warn you against this feature. As clever as it is, <code>@extend</code> still is a tricky concept that might do more harm than good, especially when poorly used. The thing is, when extending a selector, you have little to no way to answer these questions without having an in-depth knowledge of the whole codebase:</p>
  2199. <ul>
  2200. <li>where is my current selector going to be appended?</li>
  2201. <li>am I likely to be causing undesired side-effects?</li>
  2202. <li>how large is the CSS generated by this single extend?</li>
  2203. </ul>
  2204. <p>For all you know, the result could range from doing nothing to causing disastrous side-effects. Because of this, my first advice would be to avoid the <code>@extend</code> directive altogether. It might sound brutal, but at the end of the day it can save you some headaches and troubles.</p>
  2205. <p>That being said, you know the saying:</p>
  2206. <blockquote>
  2207. <p>Never say never.<br/>
  2208. — Apparently, <a href="https://github.com/HugoGiraudel/sass-guidelines/issues/31#issuecomment-69112419">not Beyonce</a>.</p>
  2209. </blockquote>
  2210. <p>There are scenarios where extending selectors might be helpful and worthwhile. Yet, always keep in mind those rules so you don’t get yourself into trouble:</p>
  2211. <ul>
  2212. <li>Use extend from within a module, not across different modules.</li>
  2213. <li>Use extend on placeholders exclusively, not on actual selectors.</li>
  2214. <li>Make sure the placeholder you extend is present as little as possible in the stylesheet.</li>
  2215. </ul>
  2216. <p>If you are going to use extend, let me also remind you that it does not play well with <code>@media</code> blocks. As you may know, Sass is unable to extend an outer selector from within a media query. When doing so, the compiler simply crashes, telling you that you cannot do such a thing. Not great. Especially since media queries are almost all we do know.</p>
  2217. <div class="code-block">
  2218. <div class="code-block__wrapper" data-syntax="scss">
  2219. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="nc">.foo</span> <span class="p">{</span>
  2220. <span class="na">content</span><span class="o">:</span> <span class="s1">'</span><span class="s2">foo'</span><span class="p">;</span>
  2221. <span class="p">}</span>
  2222. <span class="k">@media</span> <span class="nt">print</span> <span class="p">{</span>
  2223. <span class="nc">.bar</span> <span class="p">{</span>
  2224. <span class="c1">// This doesn't work. Worse: it crashes.</span>
  2225. <span class="k">@extend</span> <span class="nc">.foo</span><span class="o">;</span>
  2226. <span class="p">}</span>
  2227. <span class="p">}</span></code></pre></div>
  2228. </div>
  2229. <div class="code-block__wrapper" data-syntax="sass">
  2230. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="nc">.foo</span>
  2231. <span class="na">content</span><span class="o">:</span> <span class="s1">'</span><span class="s2">foo'</span>
  2232. <span class="k">@media</span> <span class="nt">print</span>
  2233. <span class="nc">.bar</span>
  2234. <span class="c1">// This doesn't work. Worse: it crashes.</span>
  2235. <span class="k">@extend</span> <span class="nc">.foo</span></code></pre></div>
  2236. </div>
  2237. </div>
  2238. <blockquote>
  2239. <p>You may not @extend an outer selector from within @media.<br/>
  2240. You may only @extend selectors within the same directive.</p>
  2241. </blockquote>
  2242. <div class="note">
  2243. <p>It is often said that <code>@extend</code> helps with the file size since it combines selectors rather than duplicated properties. That is true, however the difference is negligible once <a href="http://en.wikipedia.org/wiki/Gzip">Gzip</a> has done its compression.</p>
  2244. <p>That being said, if you cannot use Gzip (or any equivalent) then switching to a <code>@extend</code> approach might not be that bad as long as you know what you are doing.</p>
  2245. </div>
  2246. <p>To sum up, I would <strong>advise against using the <code>@extend</code> directive</strong>, unless under some specific circumstances, but I would not go as far as to forbid it.</p>
  2247. <h6 id="further-reading-23">Further reading</h6>
  2248. <h1 id="mixins">Mixins</h1>
  2249. <p>Mixins are one of the most used features from the whole Sass language. They are the key to reusability and DRY components. And for good reason: mixins allow authors to define styles that can be reused throughout the stylesheet without needing to resort to non-semantic classes such as <code>.float-left</code>.</p>
  2250. <p>They can contain full CSS rules and pretty much everything that is allowed anywhere in a Sass document. They can even take arguments, just like functions. Needless to say, the possibilities are endless.</p>
  2251. <p>But I feel I must warn you against abusing the power of mixins. Again, the keyword here is <em>simplicity</em>. It might be tempting to build extremely powerful mixins with massive amounts of logic. It’s called over-engineering and most developers suffer from it. Don’t over think your code, and above all keep it simple. If a mixin ends up being longer than 20 lines or so, then it should be either split into smaller chunks or completely revised.</p>
  2252. <h2 id="basics">Basics</h2>
  2253. <p>That being said, mixins are extremely useful and you should be using some. The rule of thumb is that if you happen to spot a group of CSS properties that always appear together for a reason (i.e. not a coincidence), you can put them in a mixin instead. The <a href="http://nicolasgallagher.com/micro-clearfix-hack/">micro-clearfix hack from Nicolas Gallagher</a> deserves to be put in a (argumentless) mixin for instance.</p>
  2254. <div class="code-block">
  2255. <div class="code-block__wrapper" data-syntax="scss">
  2256. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">/// Helper to clear inner floats</span>
  2257. <span class="c1">/// @author Nicolas Gallagher</span>
  2258. <span class="c1">/// @link http://nicolasgallagher.com/micro-clearfix-hack/ Micro Clearfix</span>
  2259. <span class="k">@mixin</span><span class="nf"> clearfix</span> <span class="p">{</span>
  2260. <span class="na">&amp;</span><span class="o">::</span><span class="n">after</span> <span class="p">{</span>
  2261. <span class="na">content</span><span class="o">:</span> <span class="s1">'</span><span class="s2">'</span><span class="p">;</span>
  2262. <span class="na">display</span><span class="o">:</span> <span class="n">table</span><span class="p">;</span>
  2263. <span class="na">clear</span><span class="o">:</span> <span class="no">both</span><span class="p">;</span>
  2264. <span class="p">}</span>
  2265. <span class="p">}</span></code></pre></div>
  2266. </div>
  2267. <div class="code-block__wrapper" data-syntax="sass">
  2268. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">/// Helper to clear inner floats</span>
  2269. <span class="c1">/// @author Nicolas Gallagher</span>
  2270. <span class="c1">/// @link http://nicolasgallagher.com/micro-clearfix-hack/ Micro Clearfix</span>
  2271. <span class="k">@mixin</span><span class="nf"> clearfix</span>
  2272. <span class="na">&amp;</span><span class="o">::</span><span class="n">after</span>
  2273. <span class="na">content</span><span class="o">:</span> <span class="s1">'</span><span class="s2">'</span>
  2274. <span class="na">display</span><span class="o">:</span> <span class="n">table</span>
  2275. <span class="na">clear</span><span class="o">:</span> <span class="no">both</span></code></pre></div>
  2276. </div>
  2277. </div>
  2278. <p>Another valid example would be a mixin to size an element, defining both <code>width</code> and <code>height</code> at the same time. Not only would it make the code lighter to type, but also easier to read.</p>
  2279. <div class="code-block">
  2280. <div class="code-block__wrapper" data-syntax="scss">
  2281. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">/// Helper to size an element</span>
  2282. <span class="c1">/// @author Hugo Giraudel</span>
  2283. <span class="c1">/// @param {Length} $width</span>
  2284. <span class="c1">/// @param {Length} $height</span>
  2285. <span class="k">@mixin</span><span class="nf"> size</span><span class="p">(</span><span class="nv">$width</span><span class="o">,</span> <span class="nv">$height</span><span class="o">:</span> <span class="nv">$width</span><span class="p">)</span> <span class="p">{</span>
  2286. <span class="na">width</span><span class="o">:</span> <span class="nv">$width</span><span class="p">;</span>
  2287. <span class="na">height</span><span class="o">:</span> <span class="nv">$height</span><span class="p">;</span>
  2288. <span class="p">}</span></code></pre></div>
  2289. </div>
  2290. <div class="code-block__wrapper" data-syntax="sass">
  2291. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">/// Helper to size an element</span>
  2292. <span class="c1">/// @author Hugo Giraudel</span>
  2293. <span class="c1">/// @param {Length} $width</span>
  2294. <span class="c1">/// @param {Length} $height</span>
  2295. <span class="nf">=size</span><span class="p">(</span><span class="nv">$width</span><span class="o">,</span> <span class="nv">$height</span><span class="o">:</span> <span class="nv">$width</span><span class="p">)</span>
  2296. <span class="na">width</span><span class="o">:</span> <span class="nv">$width</span>
  2297. <span class="na">height</span><span class="o">:</span> <span class="nv">$height</span></code></pre></div>
  2298. </div>
  2299. </div>
  2300. <h6 id="further-reading-24">Further reading</h6>
  2301. <h2 id="arguments-list">Arguments list</h2>
  2302. <p>When dealing with an unknown number of arguments in a mixin, always use an <code>arglist</code> rather than a list. Think of <code>arglist</code> as the 8th hidden undocumented data type from Sass that is implicitly used when passing an arbitrary number of arguments to a mixin or a function whose signature contains <code>...</code>.</p>
  2303. <div class="code-block">
  2304. <div class="code-block__wrapper" data-syntax="scss">
  2305. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="k">@mixin</span><span class="nf"> shadows</span><span class="p">(</span><span class="nv">$shadows</span><span class="o">...</span><span class="p">)</span> <span class="p">{</span>
  2306. <span class="c1">// type-of($shadows) == 'arglist'</span>
  2307. <span class="c1">// ...</span>
  2308. <span class="p">}</span></code></pre></div>
  2309. </div>
  2310. <div class="code-block__wrapper" data-syntax="sass">
  2311. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="nf">=shadows</span><span class="p">(</span><span class="nv">$shadows</span><span class="o">...</span><span class="p">)</span>
  2312. <span class="c1">// type-of($shadows) == 'arglist'</span>
  2313. <span class="c1">// ...</span></code></pre></div>
  2314. </div>
  2315. </div>
  2316. <p>Now, when building a mixin that accepts a handful of arguments (understand 3 or more), think twice before merging them out as a list or a map thinking it will be easier than passing them all one by one.</p>
  2317. <p>Sass is actually pretty clever with mixins and function declarations, so much so that you can actually pass a list or a map as an arglist to a function/mixin so that it gets parsed as a series of arguments.</p>
  2318. <div class="code-block">
  2319. <div class="code-block__wrapper" data-syntax="scss">
  2320. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="k">@mixin</span><span class="nf"> dummy</span><span class="p">(</span><span class="nv">$a</span><span class="o">,</span> <span class="nv">$b</span><span class="o">,</span> <span class="nv">$c</span><span class="p">)</span> <span class="p">{</span>
  2321. <span class="c1">// ...</span>
  2322. <span class="p">}</span>
  2323. <span class="c1">// Yep</span>
  2324. <span class="k">@include</span><span class="nd"> dummy</span><span class="p">(</span><span class="n-Pseudo">true</span><span class="o">,</span> <span class="mi">42</span><span class="o">,</span> <span class="s1">'</span><span class="s2">kittens'</span><span class="p">);</span>
  2325. <span class="c1">// Yep but nope</span>
  2326. <span class="nv">$params</span><span class="o">:</span> <span class="p">(</span><span class="n-Pseudo">true</span><span class="o">,</span> <span class="mi">42</span><span class="o">,</span> <span class="s1">'</span><span class="s2">kittens'</span><span class="p">);</span>
  2327. <span class="nv">$value</span><span class="o">:</span> <span class="nf">dummy</span><span class="p">(</span><span class="nf">nth</span><span class="p">(</span><span class="nv">$params</span><span class="o">,</span> <span class="mi">1</span><span class="p">)</span><span class="o">,</span> <span class="nf">nth</span><span class="p">(</span><span class="nv">$params</span><span class="o">,</span> <span class="mi">2</span><span class="p">)</span><span class="o">,</span> <span class="nf">nth</span><span class="p">(</span><span class="nv">$params</span><span class="o">,</span> <span class="mi">3</span><span class="p">));</span>
  2328. <span class="c1">// Yep</span>
  2329. <span class="nv">$params</span><span class="o">:</span> <span class="p">(</span><span class="n-Pseudo">true</span><span class="o">,</span> <span class="mi">42</span><span class="o">,</span> <span class="s1">'</span><span class="s2">kittens'</span><span class="p">);</span>
  2330. <span class="k">@include</span><span class="nd"> dummy</span><span class="p">(</span><span class="nv">$params</span><span class="o">...</span><span class="p">);</span>
  2331. <span class="c1">// Yep</span>
  2332. <span class="nv">$params</span><span class="o">:</span> <span class="p">(</span>
  2333. <span class="s1">'</span><span class="s2">c'</span><span class="o">:</span> <span class="s1">'</span><span class="s2">kittens'</span><span class="o">,</span>
  2334. <span class="s1">'</span><span class="s2">a'</span><span class="o">:</span> <span class="n-Pseudo">true</span><span class="o">,</span>
  2335. <span class="s1">'</span><span class="s2">b'</span><span class="o">:</span> <span class="mi">42</span><span class="o">,</span>
  2336. <span class="p">);</span>
  2337. <span class="k">@include</span><span class="nd"> dummy</span><span class="p">(</span><span class="nv">$params</span><span class="o">...</span><span class="p">);</span></code></pre></div>
  2338. </div>
  2339. <div class="code-block__wrapper" data-syntax="sass">
  2340. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="nf">=dummy</span><span class="p">(</span><span class="nv">$a</span><span class="o">,</span> <span class="nv">$b</span><span class="o">,</span> <span class="nv">$c</span><span class="p">)</span>
  2341. <span class="c1">// ...</span>
  2342. <span class="c1">// Yep</span>
  2343. <span class="nd">+dummy</span><span class="p">(</span><span class="n-Pseudo">true</span><span class="o">,</span> <span class="mi">42</span><span class="o">,</span> <span class="s1">'</span><span class="s2">kittens'</span><span class="p">)</span>
  2344. <span class="c1">// Yep but nope</span>
  2345. <span class="nv">$params</span><span class="o">:</span> <span class="p">(</span><span class="n-Pseudo">true</span><span class="o">,</span> <span class="mi">42</span><span class="o">,</span> <span class="s1">'</span><span class="s2">kittens'</span><span class="p">)</span>
  2346. <span class="nv">$value</span><span class="o">:</span> <span class="nf">dummy</span><span class="p">(</span><span class="nf">nth</span><span class="p">(</span><span class="nv">$params</span><span class="o">,</span> <span class="mi">1</span><span class="p">)</span><span class="o">,</span> <span class="nf">nth</span><span class="p">(</span><span class="nv">$params</span><span class="o">,</span> <span class="mi">2</span><span class="p">)</span><span class="o">,</span> <span class="nf">nth</span><span class="p">(</span><span class="nv">$params</span><span class="o">,</span> <span class="mi">3</span><span class="p">))</span>
  2347. <span class="c1">// Yep</span>
  2348. <span class="nv">$params</span><span class="o">:</span> <span class="p">(</span><span class="n-Pseudo">true</span><span class="o">,</span> <span class="mi">42</span><span class="o">,</span> <span class="s1">'</span><span class="s2">kittens'</span><span class="p">)</span>
  2349. <span class="nd">+dummy</span><span class="p">(</span><span class="nv">$params</span><span class="o">...</span><span class="p">)</span>
  2350. <span class="c1">// Yep</span>
  2351. <span class="nv">$params</span><span class="o">:</span> <span class="p">(</span><span class="s1">'</span><span class="s2">c'</span><span class="o">:</span> <span class="s1">'</span><span class="s2">kittens'</span><span class="o">,</span> <span class="s1">'</span><span class="s2">a'</span><span class="o">:</span> <span class="n-Pseudo">true</span><span class="o">,</span> <span class="s1">'</span><span class="s2">b'</span><span class="o">:</span> <span class="mi">42</span><span class="o">,</span><span class="p">)</span>
  2352. <span class="nd">+dummy</span><span class="p">(</span><span class="nv">$params</span><span class="o">...</span><span class="p">)</span></code></pre></div>
  2353. </div>
  2354. </div>
  2355. <h6 id="further-reading-25">Further reading</h6>
  2356. <h2 id="mixins-and-vendor-prefixes">Mixins and vendor prefixes</h2>
  2357. <p>It might be tempting to define custom mixins to handle vendor prefixes for unsupported or partially supported CSS properties. But we do not want to do this. First, if you can use <a href="https://github.com/postcss/autoprefixer">Autoprefixer</a>, use Autoprefixer. It will remove Sass code from your project, will always be up-to-date and will necessarily do a much better job than you at prefixing stuff.</p>
  2358. <p>Unfortunately, Autoprefixer is not always an option. If you use either <a href="http://bourbon.io/">Bourbon</a> or <a href="http://compass-style.org/">Compass</a>, you may already know that they both provide a collection of mixins that handle vendor prefixes for you. Use those.</p>
  2359. <p>If you cannot use Autoprefixer and use neither Bourbon nor Compass, then and only then, you can have your own mixin for prefixing CSS properties. But. Please do not build a mixin per property, manually printing each vendor.</p>
  2360. <div class="code-block">
  2361. <div class="code-block__wrapper" data-syntax="scss">
  2362. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Nope</span>
  2363. <span class="k">@mixin</span><span class="nf"> transform</span><span class="p">(</span><span class="nv">$value</span><span class="p">)</span> <span class="p">{</span>
  2364. <span class="na">-webkit-transform</span><span class="o">:</span> <span class="nv">$value</span><span class="p">;</span>
  2365. <span class="na">-moz-transform</span><span class="o">:</span> <span class="nv">$value</span><span class="p">;</span>
  2366. <span class="na">transform</span><span class="o">:</span> <span class="nv">$value</span><span class="p">;</span>
  2367. <span class="p">}</span></code></pre></div>
  2368. </div>
  2369. <div class="code-block__wrapper" data-syntax="sass">
  2370. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Nope</span>
  2371. <span class="nf">=transform</span><span class="p">(</span><span class="nv">$value</span><span class="p">)</span>
  2372. <span class="na">-webkit-transform</span><span class="o">:</span> <span class="nv">$value</span>
  2373. <span class="na">-moz-transform</span><span class="o">:</span> <span class="nv">$value</span>
  2374. <span class="na">transform</span><span class="o">:</span> <span class="nv">$value</span></code></pre></div>
  2375. </div>
  2376. </div>
  2377. <p>Do it the clever way.</p>
  2378. <div class="code-block">
  2379. <div class="code-block__wrapper" data-syntax="scss">
  2380. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">/// Mixin helper to output vendor prefixes</span>
  2381. <span class="c1">/// @access public</span>
  2382. <span class="c1">/// @author HugoGiraudel</span>
  2383. <span class="c1">/// @param {String} $property - Unprefixed CSS property</span>
  2384. <span class="c1">/// @param {*} $value - Raw CSS value</span>
  2385. <span class="c1">/// @param {List} $prefixes - List of prefixes to output</span>
  2386. <span class="k">@mixin</span><span class="nf"> prefix</span><span class="p">(</span><span class="nv">$property</span><span class="o">,</span> <span class="nv">$value</span><span class="o">,</span> <span class="nv">$prefixes</span><span class="o">:</span> <span class="p">())</span> <span class="p">{</span>
  2387. <span class="k">@each</span> <span class="err">$</span><span class="nt">prefix</span> <span class="nt">in</span> <span class="err">$</span><span class="nt">prefixes</span> <span class="p">{</span>
  2388. <span class="nt">-</span><span class="nn">#</span><span class="p">{</span><span class="err">$</span><span class="nt">prefix</span><span class="p">}</span><span class="nt">-</span><span class="nn">#</span><span class="p">{</span><span class="err">$</span><span class="nt">property</span><span class="p">}</span><span class="nd">:</span> <span class="err">$</span><span class="nt">value</span><span class="o">;</span>
  2389. <span class="p">}</span>
  2390. <span class="nn">#</span><span class="p">{</span><span class="err">$</span><span class="nt">property</span><span class="p">}</span><span class="nd">:</span> <span class="err">$</span><span class="nt">value</span><span class="o">;</span>
  2391. <span class="p">}</span></code></pre></div>
  2392. </div>
  2393. <div class="code-block__wrapper" data-syntax="sass">
  2394. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">/// Mixin helper to output vendor prefixes</span>
  2395. <span class="c1">/// @access public</span>
  2396. <span class="c1">/// @author HugoGiraudel</span>
  2397. <span class="c1">/// @param {String} $property - Unprefixed CSS property</span>
  2398. <span class="c1">/// @param {*} $value - Raw CSS value</span>
  2399. <span class="c1">/// @param {List} $prefixes - List of prefixes to output</span>
  2400. <span class="nf">=prefix</span><span class="p">(</span><span class="nv">$property</span><span class="o">,</span> <span class="nv">$value</span><span class="o">,</span> <span class="nv">$prefixes</span><span class="o">:</span> <span class="p">())</span>
  2401. <span class="k">@each</span> <span class="err">$</span><span class="nt">prefix</span> <span class="nt">in</span> <span class="err">$</span><span class="nt">prefixes</span>
  2402. <span class="na">-#{$prefix}-#{$property}</span><span class="o">:</span> <span class="nv">$value</span>
  2403. <span class="na">#{$property}</span><span class="o">:</span> <span class="nv">$value</span></code></pre></div>
  2404. </div>
  2405. </div>
  2406. <p>Then using this mixin should be very straightforward:</p>
  2407. <div class="code-block">
  2408. <div class="code-block__wrapper" data-syntax="scss">
  2409. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="nc">.foo</span> <span class="p">{</span>
  2410. <span class="k">@include</span><span class="nd"> prefix</span><span class="p">(</span><span class="n">transform</span><span class="o">,</span> <span class="nf">rotate</span><span class="p">(</span><span class="mi">90</span><span class="kt">deg</span><span class="p">)</span><span class="o">,</span> <span class="p">(</span><span class="s1">'</span><span class="s2">webkit'</span><span class="o">,</span> <span class="s1">'</span><span class="s2">ms'</span><span class="p">));</span>
  2411. <span class="p">}</span></code></pre></div>
  2412. </div>
  2413. <div class="code-block__wrapper" data-syntax="sass">
  2414. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="nc">.foo</span>
  2415. <span class="nd">+prefix</span><span class="p">(</span><span class="n">transform</span><span class="o">,</span> <span class="nf">rotate</span><span class="p">(</span><span class="mi">90</span><span class="kt">deg</span><span class="p">)</span><span class="o">,</span> <span class="p">(</span><span class="s1">'</span><span class="s2">webkit'</span><span class="o">,</span> <span class="s1">'</span><span class="s2">ms'</span><span class="p">))</span></code></pre></div>
  2416. </div>
  2417. </div>
  2418. <p>Please keep in mind this is a poor solution. For instance, it cannot deal with complex polyfills such as those required for Flexbox. In that sense, using Autoprefixer would be a far better option.</p>
  2419. <h6 id="further-reading-26">Further reading</h6>
  2420. <h1 id="conditional-statements">Conditional statements</h1>
  2421. <p>You probably already know that Sass provides conditional statements via the <code>@if</code> and <code>@else</code> directives. Unless you have some medium to complex logic in your code, there is no need for conditional statements in your everyday stylesheets. Actually, they mainly exist for libraries and frameworks.</p>
  2422. <p>Anyway, if you ever find yourself in need of them, please respect the following guidelines:</p>
  2423. <ul>
  2424. <li>No parentheses unless they are necessary;</li>
  2425. <li>Always an empty new line before <code>@if</code>;</li>
  2426. <li>Always a line break after the opening brace (<code>{</code>);</li>
  2427. <li><code>@else</code> statements on the same line as previous closing brace (<code>}</code>).</li>
  2428. <li>Always an empty new line after the last closing brace (<code>}</code>) unless the next line is a closing brace (<code>}</code>).</li>
  2429. </ul>
  2430. <div class="code-block">
  2431. <div class="code-block__wrapper" data-syntax="scss">
  2432. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Yep</span>
  2433. <span class="k">@if</span> <span class="nv">$support-legacy</span> <span class="p">{</span>
  2434. <span class="c1">// ...</span>
  2435. <span class="p">}</span> <span class="k">@else</span> <span class="p">{</span>
  2436. <span class="c1">// ...</span>
  2437. <span class="p">}</span>
  2438. <span class="c1">// Nope</span>
  2439. <span class="k">@if</span> <span class="p">(</span><span class="nv">$support-legacy</span> <span class="o">==</span> <span class="n-Pseudo">true</span><span class="p">)</span> <span class="p">{</span>
  2440. <span class="c1">// ...</span>
  2441. <span class="p">}</span>
  2442. <span class="k">@else</span> <span class="p">{</span>
  2443. <span class="c1">// ...</span>
  2444. <span class="p">}</span></code></pre></div>
  2445. </div>
  2446. <div class="code-block__wrapper" data-syntax="sass">
  2447. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Yep</span>
  2448. <span class="k">@if</span> <span class="nv">$support-legacy</span>
  2449. <span class="c1">// ...</span>
  2450. <span class="k">@else</span>
  2451. <span class="c1">// ...</span>
  2452. <span class="c1">// Nope</span>
  2453. <span class="k">@if</span> <span class="p">(</span><span class="nv">$support-legacy</span> <span class="o">==</span> <span class="n-Pseudo">true</span><span class="p">)</span>
  2454. <span class="c1">// ...</span>
  2455. <span class="k">@else</span>
  2456. <span class="c1">// ...</span></code></pre></div>
  2457. </div>
  2458. </div>
  2459. <p>When testing for a falsy value, always use the <code>not</code> keyword rather than testing against <code>false</code> or <code>null</code>.</p>
  2460. <div class="code-block">
  2461. <div class="code-block__wrapper" data-syntax="scss">
  2462. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Yep</span>
  2463. <span class="k">@if</span> <span class="ow">not</span> <span class="nf">index</span><span class="p">(</span><span class="nv">$list</span><span class="o">,</span> <span class="nv">$item</span><span class="p">)</span> <span class="p">{</span>
  2464. <span class="c1">// ...</span>
  2465. <span class="p">}</span>
  2466. <span class="c1">// Nope</span>
  2467. <span class="k">@if</span> <span class="nf">index</span><span class="p">(</span><span class="nv">$list</span><span class="o">,</span> <span class="nv">$item</span><span class="p">)</span> <span class="o">==</span> <span class="n">null</span> <span class="p">{</span>
  2468. <span class="c1">// ...</span>
  2469. <span class="p">}</span></code></pre></div>
  2470. </div>
  2471. <div class="code-block__wrapper" data-syntax="sass">
  2472. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Yep</span>
  2473. <span class="k">@if</span> <span class="ow">not</span> <span class="nf">index</span><span class="p">(</span><span class="nv">$list</span><span class="o">,</span> <span class="nv">$item</span><span class="p">)</span>
  2474. <span class="c1">// ...</span>
  2475. <span class="c1">// Nope</span>
  2476. <span class="k">@if</span> <span class="nf">index</span><span class="p">(</span><span class="nv">$list</span><span class="o">,</span> <span class="nv">$item</span><span class="p">)</span> <span class="o">==</span> <span class="n">null</span>
  2477. <span class="c1">// ...</span></code></pre></div>
  2478. </div>
  2479. </div>
  2480. <p>Always put the variable part on the left side of the statement, and the (un)expected result on the right. Reversed conditional statements often are more difficult to read, especially to unexperienced developers.</p>
  2481. <div class="code-block">
  2482. <div class="code-block__wrapper" data-syntax="scss">
  2483. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Yep</span>
  2484. <span class="k">@if</span> <span class="nv">$value</span> <span class="o">==</span> <span class="mi">42</span> <span class="p">{</span>
  2485. <span class="c1">// ...</span>
  2486. <span class="p">}</span>
  2487. <span class="c1">// Nope</span>
  2488. <span class="k">@if</span> <span class="mi">42</span> <span class="o">==</span> <span class="nv">$value</span> <span class="p">{</span>
  2489. <span class="c1">// ...</span>
  2490. <span class="p">}</span></code></pre></div>
  2491. </div>
  2492. <div class="code-block__wrapper" data-syntax="sass">
  2493. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Yep</span>
  2494. <span class="k">@if</span> <span class="nv">$value</span> <span class="o">==</span> <span class="mi">42</span>
  2495. <span class="c1">// ...</span>
  2496. <span class="c1">// Nope</span>
  2497. <span class="k">@if</span> <span class="mi">42</span> <span class="o">==</span> <span class="nv">$value</span>
  2498. <span class="c1">// ...</span></code></pre></div>
  2499. </div>
  2500. </div>
  2501. <p>When using conditional statements within a function to return a different result based on some condition, always make sure the function still has a <code>@return</code> statement outside of any conditional block.</p>
  2502. <div class="code-block">
  2503. <div class="code-block__wrapper" data-syntax="scss">
  2504. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">// Yep</span>
  2505. <span class="k">@function</span> <span class="nt">dummy</span><span class="o">(</span><span class="err">$</span><span class="nt">condition</span><span class="o">)</span> <span class="p">{</span>
  2506. <span class="k">@if</span> <span class="nv">$condition</span> <span class="p">{</span>
  2507. <span class="k">@return</span> <span class="nt">true</span><span class="o">;</span>
  2508. <span class="p">}</span>
  2509. <span class="k">@return</span> <span class="nt">false</span><span class="o">;</span>
  2510. <span class="p">}</span>
  2511. <span class="c1">// Nope</span>
  2512. <span class="k">@function</span> <span class="nt">dummy</span><span class="o">(</span><span class="err">$</span><span class="nt">condition</span><span class="o">)</span> <span class="p">{</span>
  2513. <span class="k">@if</span> <span class="nv">$condition</span> <span class="p">{</span>
  2514. <span class="k">@return</span> <span class="nt">true</span><span class="o">;</span>
  2515. <span class="p">}</span> <span class="k">@else</span> <span class="p">{</span>
  2516. <span class="k">@return</span> <span class="nt">false</span><span class="o">;</span>
  2517. <span class="p">}</span>
  2518. <span class="p">}</span></code></pre></div>
  2519. </div>
  2520. <div class="code-block__wrapper" data-syntax="sass">
  2521. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">// Yep</span>
  2522. <span class="k">@function</span> <span class="nt">dummy</span><span class="o">(</span><span class="err">$</span><span class="nt">condition</span><span class="o">)</span>
  2523. <span class="k">@if</span> <span class="nv">$condition</span>
  2524. <span class="k">@return</span> <span class="nt">true</span>
  2525. <span class="k">@return</span> <span class="nt">false</span><span class="o">;</span>
  2526. <span class="c1">// Nope</span>
  2527. <span class="k">@function</span> <span class="nt">dummy</span><span class="o">(</span><span class="err">$</span><span class="nt">condition</span><span class="o">)</span>
  2528. <span class="k">@if</span> <span class="nv">$condition</span>
  2529. <span class="k">@return</span> <span class="nt">true</span>
  2530. <span class="k">@else</span>
  2531. <span class="k">@return</span> <span class="nt">false</span></code></pre></div>
  2532. </div>
  2533. </div>
  2534. <h1 id="loops">Loops</h1>
  2535. <p>Because Sass provides complex data structures such as <a href="#lists">lists</a> and <a href="#maps">maps</a>, it is no surprise that it also gives a way for authors to iterate over those entities.</p>
  2536. <p>However, the presence of loops usually implies moderately complex logic that probably does not belong to Sass. Before using a loop, make sure it makes sense and that it actually solves an issue.</p>
  2537. <h2 id="each">Each</h2>
  2538. <p>The <code>@each</code> loop is definitely the most-used out of the three loops provided by Sass. It provides a clean API to iterate over a list or a map.</p>
  2539. <div class="code-block">
  2540. <div class="code-block__wrapper" data-syntax="scss">
  2541. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="k">@each</span> <span class="err">$</span><span class="nt">theme</span> <span class="nt">in</span> <span class="err">$</span><span class="nt">themes</span> <span class="p">{</span>
  2542. <span class="nc">.section-</span><span class="si">#{</span><span class="nv">$theme</span><span class="si">}</span> <span class="p">{</span>
  2543. <span class="na">background-color</span><span class="o">:</span> <span class="nf">map-get</span><span class="p">(</span><span class="nv">$colors</span><span class="o">,</span> <span class="nv">$theme</span><span class="p">);</span>
  2544. <span class="p">}</span>
  2545. <span class="p">}</span></code></pre></div>
  2546. </div>
  2547. <div class="code-block__wrapper" data-syntax="sass">
  2548. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="k">@each</span> <span class="err">$</span><span class="nt">theme</span> <span class="nt">in</span> <span class="err">$</span><span class="nt">themes</span>
  2549. <span class="nc">.section-</span><span class="si">#{</span><span class="nv">$theme</span><span class="si">}</span>
  2550. <span class="na">background-color</span><span class="o">:</span> <span class="nf">map-get</span><span class="p">(</span><span class="nv">$colors</span><span class="o">,</span> <span class="nv">$theme</span><span class="p">)</span></code></pre></div>
  2551. </div>
  2552. </div>
  2553. <p>When iterating on a map, always use <code>$key</code> and <code>$value</code> as variable names to enforce consistency.</p>
  2554. <div class="code-block">
  2555. <div class="code-block__wrapper" data-syntax="scss">
  2556. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="k">@each</span> <span class="err">$</span><span class="nt">key</span><span class="o">,</span> <span class="err">$</span><span class="nt">value</span> <span class="nt">in</span> <span class="err">$</span><span class="nt">map</span> <span class="p">{</span>
  2557. <span class="nc">.section-</span><span class="si">#{</span><span class="nv">$key</span><span class="si">}</span> <span class="p">{</span>
  2558. <span class="na">background-color</span><span class="o">:</span> <span class="nv">$value</span><span class="p">;</span>
  2559. <span class="p">}</span>
  2560. <span class="p">}</span></code></pre></div>
  2561. </div>
  2562. <div class="code-block__wrapper" data-syntax="sass">
  2563. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="k">@each</span> <span class="err">$</span><span class="nt">key</span><span class="o">,</span> <span class="err">$</span><span class="nt">value</span> <span class="nt">in</span> <span class="err">$</span><span class="nt">map</span>
  2564. <span class="nc">.section-</span><span class="si">#{</span><span class="nv">$key</span><span class="si">}</span>
  2565. <span class="na">background-color</span><span class="o">:</span> <span class="nv">$value</span></code></pre></div>
  2566. </div>
  2567. </div>
  2568. <p>Also be sure to respect those guidelines to preserve readability:</p>
  2569. <ul>
  2570. <li>Always an empty new line before <code>@each</code>;</li>
  2571. <li>Always an empty new line after the closing brace (<code>}</code>) unless the next line is a closing brace (<code>}</code>).</li>
  2572. </ul>
  2573. <h2 id="for">For</h2>
  2574. <p>The <code>@for</code> loop might be useful when combined with CSS’ <code>:nth-*</code> pseudo-classes. Except for these scenarios, prefer an <code>@each</code> loop if you <em>have to</em> iterate over something.</p>
  2575. <div class="code-block">
  2576. <div class="code-block__wrapper" data-syntax="scss">
  2577. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="k">@for</span> <span class="nv">$i</span> <span class="ow">from</span> <span class="mi">1</span> <span class="ow">through</span> <span class="mi">10</span> <span class="p">{</span>
  2578. <span class="nc">.foo</span><span class="nd">:nth-of-type</span><span class="o">(</span><span class="nn">#</span><span class="p">{</span><span class="err">$</span><span class="nt">i</span><span class="p">}</span><span class="o">)</span> <span class="p">{</span>
  2579. <span class="na">border-color</span><span class="o">:</span> <span class="nf">hsl</span><span class="p">(</span><span class="nv">$i</span> <span class="o">*</span> <span class="mi">36</span><span class="o">,</span> <span class="mi">50</span><span class="kt">%</span><span class="o">,</span> <span class="mi">50</span><span class="kt">%</span><span class="p">);</span>
  2580. <span class="p">}</span>
  2581. <span class="p">}</span></code></pre></div>
  2582. </div>
  2583. <div class="code-block__wrapper" data-syntax="sass">
  2584. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="k">@for</span> <span class="nv">$i</span> <span class="ow">from</span> <span class="mi">1</span> <span class="ow">through</span> <span class="mi">10</span>
  2585. <span class="nc">.foo</span><span class="nd">:nth-of-type</span><span class="o">(</span><span class="nn">#</span><span class="err">{$</span><span class="nt">i</span><span class="err">}</span><span class="o">)</span>
  2586. <span class="na">border-color</span><span class="o">:</span> <span class="nf">hsl</span><span class="p">(</span><span class="nv">$i</span> <span class="o">*</span> <span class="mi">36</span><span class="o">,</span> <span class="mi">50</span><span class="kt">%</span><span class="o">,</span> <span class="mi">50</span><span class="kt">%</span><span class="p">)</span></code></pre></div>
  2587. </div>
  2588. </div>
  2589. <p>Always use <code>$i</code> as a variable name to stick to the usual convention and unless you have a really good reason to, never use the <code>to</code> keyword: always use <code>through</code>. Many developers do not even know Sass offers this variation; using it might lead to confusion.</p>
  2590. <p>Also be sure to respect those guidelines to preserve readability:</p>
  2591. <ul>
  2592. <li>Always an empty new line before <code>@for</code>;</li>
  2593. <li>Always an empty new line after the closing brace (<code>}</code>) unless the next line is a closing brace (<code>}</code>).</li>
  2594. </ul>
  2595. <h2 id="while">While</h2>
  2596. <p>The <code>@while</code> loop has absolutely no use case in a real Sass project, especially since there is no way to break a loop from the inside. <strong>Do not use it</strong>.</p>
  2597. <h1 id="warnings-and-errors">Warnings and Errors</h1>
  2598. <p>If there is a feature that is often overlooked by Sass developers, it is the ability to dynamically output warnings and errors. Indeed, Sass comes with three custom directives to print content in the standard output system (CLI, compiling app…):</p>
  2599. <p>Let’s put <code>@debug</code> aside since it is clearly intended to debug SassScript, which is not our point here. We are then left with <code>@warn</code> and <code>@error</code> which are noticeably identical except that one stops the compiler while the other does not. I’ll let you guess which does what.</p>
  2600. <p>Now, there is a lot of room in a Sass project for warnings and errors. Basically any mixin or function expecting a specific type or argument could throw an error if something went wrong, or display a warning when doing an assumption.</p>
  2601. <h6 id="further-reading-27">Further reading</h6>
  2602. <h2 id="warnings">Warnings</h2>
  2603. <p>Take this function from <a href="https://github.com/sass-mq/sass-mq">Sass-MQ</a> attempting to convert a <code>px</code> value to <code>em</code>, for instance:</p>
  2604. <div class="code-block">
  2605. <div class="code-block__wrapper" data-syntax="scss">
  2606. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="k">@function</span> <span class="nt">mq-px2em</span><span class="o">(</span><span class="err">$</span><span class="nt">px</span><span class="o">,</span> <span class="err">$</span><span class="nt">base-font-size</span><span class="nd">:</span> <span class="err">$</span><span class="nt">mq-base-font-size</span><span class="o">)</span> <span class="p">{</span>
  2607. <span class="k">@if</span> <span class="nf">unitless</span><span class="p">(</span><span class="nv">$px</span><span class="p">)</span> <span class="p">{</span>
  2608. <span class="k">@warn</span> <span class="s1">'</span><span class="s2">Assuming </span><span class="si">#{</span><span class="nv">$px</span><span class="si">}</span><span class="s2"> to be in pixels, attempting to convert it into pixels.'</span><span class="p">;</span>
  2609. <span class="k">@return</span> <span class="nt">mq-px2em</span><span class="o">(</span><span class="err">$</span><span class="nt">px</span> <span class="o">+</span> <span class="nt">0px</span><span class="o">);</span>
  2610. <span class="p">}</span> <span class="k">@else</span> <span class="nt">if</span> <span class="nt">unit</span><span class="o">(</span><span class="err">$</span><span class="nt">px</span><span class="o">)</span> <span class="o">==</span> <span class="nt">em</span> <span class="p">{</span>
  2611. <span class="k">@return</span> <span class="err">$</span><span class="nt">px</span><span class="o">;</span>
  2612. <span class="p">}</span>
  2613. <span class="k">@return</span> <span class="o">(</span><span class="err">$</span><span class="nt">px</span> <span class="o">/</span> <span class="err">$</span><span class="nt">base-font-size</span><span class="o">)</span> <span class="o">*</span> <span class="nt">1em</span><span class="o">;</span>
  2614. <span class="p">}</span></code></pre></div>
  2615. </div>
  2616. <div class="code-block__wrapper" data-syntax="sass">
  2617. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="k">@function</span> <span class="nt">mq-px2em</span><span class="o">(</span><span class="err">$</span><span class="nt">px</span><span class="o">,</span> <span class="err">$</span><span class="nt">base-font-size</span><span class="nd">:</span> <span class="err">$</span><span class="nt">mq-base-font-size</span><span class="o">)</span>
  2618. <span class="k">@if</span> <span class="nf">unitless</span><span class="p">(</span><span class="nv">$px</span><span class="p">)</span>
  2619. <span class="k">@warn</span> <span class="s1">'</span><span class="s2">Assuming </span><span class="si">#{</span><span class="nv">$px</span><span class="si">}</span><span class="s2"> to be in pixels, attempting to convert it into pixels.'</span>
  2620. <span class="k">@return</span> <span class="nt">mq-px2em</span><span class="o">(</span><span class="err">$</span><span class="nt">px</span> <span class="o">+</span> <span class="nt">0px</span><span class="o">)</span>
  2621. <span class="k">@else</span> <span class="nt">if</span> <span class="nt">unit</span><span class="o">(</span><span class="err">$</span><span class="nt">px</span><span class="o">)</span> <span class="o">==</span> <span class="nt">em</span>
  2622. <span class="k">@return</span> <span class="err">$</span><span class="nt">px</span>
  2623. <span class="k">@return</span> <span class="o">(</span><span class="err">$</span><span class="nt">px</span> <span class="o">/</span> <span class="err">$</span><span class="nt">base-font-size</span><span class="o">)</span> <span class="o">*</span> <span class="nt">1em</span></code></pre></div>
  2624. </div>
  2625. </div>
  2626. <p>If the value happens to be unitless, the function assumes the value is meant to be expressed in pixels. At this point, an assumption may be risky so the user should be warned that the software did something that could be considered unexpected.</p>
  2627. <h2 id="errors">Errors</h2>
  2628. <p>Errors, unlike warnings, prevent the compiler from going any further. Basically, they stop the compilation and display a message in the output stream as well as the stack trace, which is handy for debugging. Because of this, errors should be thrown when there is no way for the program to keep running. When possible, try to work around the issue and display a warning instead.</p>
  2629. <p>As an example, let’s say you build a getter function to access values from a specific map. You could throw an error if the requested key does not exist in the map.</p>
  2630. <div class="code-block">
  2631. <div class="code-block__wrapper" data-syntax="scss">
  2632. <div class="highlight"><pre><code class="language-scss" data-lang="scss"><span class="c1">/// Z-indexes map, gathering all Z layers of the application</span>
  2633. <span class="c1">/// @access private</span>
  2634. <span class="c1">/// @type Map</span>
  2635. <span class="c1">/// @prop {String} key - Layer’s name</span>
  2636. <span class="c1">/// @prop {Number} value - Z value mapped to the key</span>
  2637. <span class="nv">$z-indexes</span><span class="o">:</span> <span class="p">(</span>
  2638. <span class="s1">'</span><span class="s2">modal'</span><span class="o">:</span> <span class="mi">5000</span><span class="o">,</span>
  2639. <span class="s1">'</span><span class="s2">dropdown'</span><span class="o">:</span> <span class="mi">4000</span><span class="o">,</span>
  2640. <span class="s1">'</span><span class="s2">default'</span><span class="o">:</span> <span class="mi">1</span><span class="o">,</span>
  2641. <span class="s1">'</span><span class="s2">below'</span><span class="o">:</span> <span class="mi">-1</span><span class="o">,</span>
  2642. <span class="p">);</span>
  2643. <span class="c1">/// Get a z-index value from a layer name</span>
  2644. <span class="c1">/// @access public</span>
  2645. <span class="c1">/// @param {String} $layer - Layer's name</span>
  2646. <span class="c1">/// @return {Number}</span>
  2647. <span class="c1">/// @require $z-indexes</span>
  2648. <span class="k">@function</span> <span class="nt">z</span><span class="o">(</span><span class="err">$</span><span class="nt">layer</span><span class="o">)</span> <span class="p">{</span>
  2649. <span class="k">@if</span> <span class="ow">not</span> <span class="nf">map-has-key</span><span class="p">(</span><span class="nv">$z-indexes</span><span class="o">,</span> <span class="nv">$layer</span><span class="p">)</span> <span class="p">{</span>
  2650. <span class="k">@error</span> <span class="s1">'</span><span class="s2">There is no layer named `</span><span class="si">#{</span><span class="nv">$layer</span><span class="si">}</span><span class="s2">` in $z-indexes. '</span>
  2651. <span class="o">+</span> <span class="s1">'</span><span class="s2">Layer should be one of </span><span class="si">#{</span><span class="nf">map-keys</span><span class="p">(</span><span class="nv">$z-indexes</span><span class="p">)</span><span class="si">}</span><span class="s2">.'</span><span class="o">;</span>
  2652. <span class="p">}</span>
  2653. <span class="k">@return</span> <span class="nt">map-get</span><span class="o">(</span><span class="err">$</span><span class="nt">z-indexes</span><span class="o">,</span> <span class="err">$</span><span class="nt">layer</span><span class="o">);</span>
  2654. <span class="p">}</span></code></pre></div>
  2655. </div>
  2656. <div class="code-block__wrapper" data-syntax="sass">
  2657. <div class="highlight"><pre><code class="language-sass" data-lang="sass"><span class="c1">/// Z-indexes map, gathering all Z layers of the application</span>
  2658. <span class="c1">/// @access private</span>
  2659. <span class="c1">/// @type Map</span>
  2660. <span class="c1">/// @prop {String} key - Layer's name</span>
  2661. <span class="c1">/// @prop {Number} value - Z value mapped to the key</span>
  2662. <span class="na">$z-indexes</span><span class="o">:</span> <span class="p">(</span><span class="s1">'</span><span class="s2">modal'</span><span class="o">:</span> <span class="mi">5000</span><span class="o">,</span> <span class="s1">'</span><span class="s2">dropdown'</span><span class="o">:</span> <span class="mi">4000</span><span class="o">,</span> <span class="s1">'</span><span class="s2">default'</span><span class="o">:</span> <span class="mi">1</span><span class="o">,</span> <span class="s1">'</span><span class="s2">below'</span><span class="o">:</span> <span class="mi">-1</span><span class="o">,</span><span class="p">)</span>
  2663. <span class="c1">/// Get a z-index value from a layer name</span>
  2664. <span class="c1">/// @access public</span>
  2665. <span class="c1">/// @param {String} $layer - Layer's name</span>
  2666. <span class="c1">/// @return {Number}</span>
  2667. <span class="c1">/// @require $z-indexes</span>
  2668. <span class="k">@function</span> <span class="nt">z</span><span class="o">(</span><span class="err">$</span><span class="nt">layer</span><span class="o">)</span>
  2669. <span class="k">@if</span> <span class="ow">not</span> <span class="nf">map-has-key</span><span class="p">(</span><span class="nv">$z-indexes</span><span class="o">,</span> <span class="nv">$layer</span><span class="p">)</span>
  2670. <span class="k">@error</span> <span class="s1">'</span><span class="s2">There is no layer named `</span><span class="si">#{</span><span class="nv">$layer</span><span class="si">}</span><span class="s2">` in $z-indexes. '</span>
  2671. <span class="o">+</span> <span class="s1">'</span><span class="s2">Layer should be one of </span><span class="si">#{</span><span class="nf">map-keys</span><span class="p">(</span><span class="nv">$z-indexes</span><span class="p">)</span><span class="si">}</span><span class="s2">.'</span>
  2672. <span class="k">@return</span> <span class="nt">map-get</span><span class="o">(</span><span class="err">$</span><span class="nt">z-indexes</span><span class="o">,</span> <span class="err">$</span><span class="nt">layer</span><span class="o">)</span></code></pre></div>
  2673. </div>
  2674. </div>
  2675. <p>What’s nice about a CSS preprocessor as popular as Sass is that it comes with a whole ecosystem of frameworks, plugins, libraries and tools. After 8 years of existence, we are getting closer and closer to the point where <a href="http://hugogiraudel.com/2014/10/27/rethinking-atwoods-law/">everything that can be written in Sass has been written in Sass</a>.</p>
  2676. <p>However my advice would to be to lower the number of dependencies to the strict minimum. Managing dependencies is some sort of hell you don’t want to be part of. Plus, there is little to no need for external dependencies when it comes to Sass.</p>
  2677. <h2 id="compass">Compass</h2>
  2678. <p><a href="http://compass-style.org/">Compass</a> is the main Sass framework out there. Developed by <a href="https://twitter.com/chriseppstein">Chris Eppstein</a>, one of the two core designers of Sass, I don’t see it dramatically losing in popularity for a while, if you want my opinion.</p>
  2679. <p>Still, I do not use Compass anymore, the main reason is that it slows Sass down a lot. Ruby Sass is quite slow in itself, so adding more Ruby and more Sass on top of it doesn’t really help.</p>
  2680. <p>The thing is, we use very little from the whole framework. Compass is huge. Cross-browser compatibility mixins is just the tip of the iceberg. Math functions, image helpers, spriting… There is so much that can be done with this great piece of software.</p>
  2681. <p>Unfortunately, this is all sugar and there is no killer feature in there. An exception could be made of the sprite builder which is <em>really great</em>, but <a href="https://github.com/filamentgroup/grunticon">Grunticon</a> and <a href="http://grumpicon.com/">Grumpicon</a> do the job as well, and have the benefit of being pluggable in the build process.</p>
  2682. <p>Anyway, I do not forbid the use of Compass although I would not recommend it either, especially since it is not LibSass-compatible (even if efforts have been made in that direction). If you feel better using it, fair enough, but I don’t think you’ll get much from it at the end of the day.</p>
  2683. <div class="note">
  2684. <p>Ruby Sass is currently going under some outstanding optimizations that are specifically targeted at logic-heavy styles with many functions and mixins. They should dramatically improve performance to the point where Compass and other frameworks might not be slowing Sass anymore.</p>
  2685. </div>
  2686. <h6 id="further-reading-28">Further reading</h6>
  2687. <h2 id="grid-systems">Grid systems</h2>
  2688. <p>Not using a grid system is not an option now that Responsive Web Design is all over the place. To make designs look consistent and solid across all sizes, we use some sort of grid to lay out the elements. To avoid having to code this grid work over and over again, some brilliant minds made theirs reusable.</p>
  2689. <p>Let me put this straight: I am not a big fan of grid systems. Of course I do see the potential, but I think most of them are completely overkill and are mostly used to draw red columns on a white background in nerdy designers’ speaker decks. When is the last time you thought <em>thank-God-I-have-this-tool-to-build-this-2-5-3.1-π-grid</em>? That’s right, never. Because in most cases, you just want the usual regular 12-columns grid, nothing fancy.</p>
  2690. <p>If you are using a CSS framework for your project like <a href="http://getbootstrap.com/">Bootstrap</a> or <a href="http://foundation.zurb.com/">Foundation</a>, chances are high it includes a grid system already in which case I would recommend to use it to avoid having to deal with yet another dependency.</p>
  2691. <p>If you are not tied to a specific grid system, you will be pleased to know there are two top-notch Sass powered grid engines out there: <a href="http://susy.oddbird.net/">Susy</a> and <a href="http://singularity.gs/">Singularity</a>. Both do much more than you will ever need so you can pick the one you prefer between these two and be sure all your edge cases—even the most nifty ones—will be covered. If you ask me, Susy has a slightly better community, but that’s my opinion.</p>
  2692. <p>Or you can head over to something a bit more casual, like <a href="https://github.com/csswizardry/csswizardry-grids">csswizardry-grids</a>. All in all, the choice will not have much of an impact on your coding style, so this is pretty much up to you at this point.</p>
  2693. <h6 id="further-reading-29">Further reading</h6>
  2694. <h2 id="scss-lint">SCSS-lint</h2>
  2695. <p>Linting code is very important. Usually, following guidelines from a styleguide helps reducing the amount of code quality mistakes but nobody’s perfect and there are always things to improve. So you could say that linting code is as important as commenting it.</p>
  2696. <p><a href="https://github.com/causes/scss-lint">SCSS-lint</a> is a tool to help you keep your SCSS files clean and readable. It is fully customisable and easy to integrate with your own tools.</p>
  2697. <p>Fortunately, SCSS-lint recommendations are very similar to those described in this document. In order to configure SCSS-lint according to Sass Guidelines, may I recommend the following setup:</p>
  2698. <div class="highlight"><pre><code class="language-yaml" data-lang="yaml"><span class="c1"># For SCSS-Lint v0.32.0</span>
  2699. <span class="l-Scalar-Plain">linters</span><span class="p-Indicator">:</span>
  2700. <span class="l-Scalar-Plain">BangFormat</span><span class="p-Indicator">:</span>
  2701. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2702. <span class="l-Scalar-Plain">space_before_bang</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2703. <span class="l-Scalar-Plain">space_after_bang</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">false</span>
  2704. <span class="l-Scalar-Plain">BorderZero</span><span class="p-Indicator">:</span>
  2705. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2706. <span class="l-Scalar-Plain">ColorKeyword</span><span class="p-Indicator">:</span>
  2707. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">false</span>
  2708. <span class="l-Scalar-Plain">Comment</span><span class="p-Indicator">:</span>
  2709. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">false</span>
  2710. <span class="l-Scalar-Plain">DebugStatement</span><span class="p-Indicator">:</span>
  2711. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2712. <span class="l-Scalar-Plain">DeclarationOrder</span><span class="p-Indicator">:</span>
  2713. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2714. <span class="l-Scalar-Plain">DuplicateProperty</span><span class="p-Indicator">:</span>
  2715. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">false</span>
  2716. <span class="l-Scalar-Plain">ElsePlacement</span><span class="p-Indicator">:</span>
  2717. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2718. <span class="l-Scalar-Plain">style</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">same_line</span>
  2719. <span class="l-Scalar-Plain">EmptyLineBetweenBlocks</span><span class="p-Indicator">:</span>
  2720. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2721. <span class="l-Scalar-Plain">ignore_single_line_blocks</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">false</span>
  2722. <span class="l-Scalar-Plain">EmptyRule</span><span class="p-Indicator">:</span>
  2723. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2724. <span class="l-Scalar-Plain">FinalNewline</span><span class="p-Indicator">:</span>
  2725. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2726. <span class="l-Scalar-Plain">present</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2727. <span class="l-Scalar-Plain">HexLength</span><span class="p-Indicator">:</span>
  2728. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2729. <span class="l-Scalar-Plain">style</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">short</span>
  2730. <span class="l-Scalar-Plain">HexNotation</span><span class="p-Indicator">:</span>
  2731. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2732. <span class="l-Scalar-Plain">style</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">lowercase</span>
  2733. <span class="l-Scalar-Plain">HexValidation</span><span class="p-Indicator">:</span>
  2734. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2735. <span class="l-Scalar-Plain">IdSelector</span><span class="p-Indicator">:</span>
  2736. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2737. <span class="l-Scalar-Plain">ImportPath</span><span class="p-Indicator">:</span>
  2738. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2739. <span class="l-Scalar-Plain">leading_underscore</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">false</span>
  2740. <span class="l-Scalar-Plain">filename_extension</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">false</span>
  2741. <span class="l-Scalar-Plain">Indentation</span><span class="p-Indicator">:</span>
  2742. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2743. <span class="l-Scalar-Plain">character</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">space</span>
  2744. <span class="l-Scalar-Plain">width</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">2</span>
  2745. <span class="l-Scalar-Plain">LeadingZero</span><span class="p-Indicator">:</span>
  2746. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2747. <span class="l-Scalar-Plain">style</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">include_zero</span>
  2748. <span class="l-Scalar-Plain">MergeableSelector</span><span class="p-Indicator">:</span>
  2749. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">false</span>
  2750. <span class="l-Scalar-Plain">force_nesting</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">false</span>
  2751. <span class="l-Scalar-Plain">NameFormat</span><span class="p-Indicator">:</span>
  2752. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2753. <span class="l-Scalar-Plain">convention</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">hyphenated_lowercase</span>
  2754. <span class="l-Scalar-Plain">allow_leading_underscore</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2755. <span class="l-Scalar-Plain">NestingDepth</span><span class="p-Indicator">:</span>
  2756. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2757. <span class="l-Scalar-Plain">max_depth</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">3</span>
  2758. <span class="l-Scalar-Plain">PlaceholderInExtend</span><span class="p-Indicator">:</span>
  2759. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2760. <span class="l-Scalar-Plain">PropertySortOrder</span><span class="p-Indicator">:</span>
  2761. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">false</span>
  2762. <span class="l-Scalar-Plain">ignore_unspecified</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">false</span>
  2763. <span class="l-Scalar-Plain">PropertySpelling</span><span class="p-Indicator">:</span>
  2764. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2765. <span class="l-Scalar-Plain">extra_properties</span><span class="p-Indicator">:</span> <span class="p-Indicator">[]</span>
  2766. <span class="l-Scalar-Plain">QualifyingElement</span><span class="p-Indicator">:</span>
  2767. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2768. <span class="l-Scalar-Plain">allow_element_with_attribute</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">false</span>
  2769. <span class="l-Scalar-Plain">allow_element_with_class</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">false</span>
  2770. <span class="l-Scalar-Plain">allow_element_with_id</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">false</span>
  2771. <span class="l-Scalar-Plain">SelectorDepth</span><span class="p-Indicator">:</span>
  2772. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2773. <span class="l-Scalar-Plain">max_depth</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">3</span>
  2774. <span class="l-Scalar-Plain">SelectorFormat</span><span class="p-Indicator">:</span>
  2775. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2776. <span class="l-Scalar-Plain">convention</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">hyphenated_lowercase</span>
  2777. <span class="l-Scalar-Plain">class_convention</span><span class="p-Indicator">:</span> <span class="s">'^(?:u|is|has)\-[a-z][a-zA-Z0-9]*$|^(?!u|is|has)[a-zA-Z][a-zA-Z0-9]*(?:\-[a-z][a-zA-Z0-9]*)?(?:\-\-[a-z][a-zA-Z0-9]*)?$'</span>
  2778. <span class="l-Scalar-Plain">Shorthand</span><span class="p-Indicator">:</span>
  2779. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2780. <span class="l-Scalar-Plain">SingleLinePerProperty</span><span class="p-Indicator">:</span>
  2781. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2782. <span class="l-Scalar-Plain">allow_single_line_rule_sets</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">false</span>
  2783. <span class="l-Scalar-Plain">SingleLinePerSelector</span><span class="p-Indicator">:</span>
  2784. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2785. <span class="l-Scalar-Plain">SpaceAfterComma</span><span class="p-Indicator">:</span>
  2786. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2787. <span class="l-Scalar-Plain">SpaceAfterPropertyColon</span><span class="p-Indicator">:</span>
  2788. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2789. <span class="l-Scalar-Plain">style</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">one_space</span>
  2790. <span class="l-Scalar-Plain">SpaceAfterPropertyName</span><span class="p-Indicator">:</span>
  2791. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2792. <span class="l-Scalar-Plain">SpaceBeforeBrace</span><span class="p-Indicator">:</span>
  2793. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2794. <span class="l-Scalar-Plain">style</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">space</span>
  2795. <span class="l-Scalar-Plain">allow_single_line_padding</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2796. <span class="l-Scalar-Plain">SpaceBetweenParens</span><span class="p-Indicator">:</span>
  2797. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2798. <span class="l-Scalar-Plain">spaces</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">0</span>
  2799. <span class="l-Scalar-Plain">StringQuotes</span><span class="p-Indicator">:</span>
  2800. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2801. <span class="l-Scalar-Plain">style</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">single_quotes</span>
  2802. <span class="l-Scalar-Plain">TrailingSemicolon</span><span class="p-Indicator">:</span>
  2803. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2804. <span class="l-Scalar-Plain">TrailingZero</span><span class="p-Indicator">:</span>
  2805. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2806. <span class="l-Scalar-Plain">UnnecessaryMantissa</span><span class="p-Indicator">:</span>
  2807. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2808. <span class="l-Scalar-Plain">UnnecessaryParentReference</span><span class="p-Indicator">:</span>
  2809. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2810. <span class="l-Scalar-Plain">UrlFormat</span><span class="p-Indicator">:</span>
  2811. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">false</span>
  2812. <span class="l-Scalar-Plain">UrlQuotes</span><span class="p-Indicator">:</span>
  2813. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2814. <span class="l-Scalar-Plain">VendorPrefixes</span><span class="p-Indicator">:</span>
  2815. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
  2816. <span class="l-Scalar-Plain">identifier_list</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">base</span>
  2817. <span class="l-Scalar-Plain">include</span><span class="p-Indicator">:</span> <span class="p-Indicator">[]</span>
  2818. <span class="l-Scalar-Plain">exclude</span><span class="p-Indicator">:</span> <span class="p-Indicator">[]</span>
  2819. <span class="l-Scalar-Plain">ZeroUnit</span><span class="p-Indicator">:</span>
  2820. <span class="l-Scalar-Plain">enabled</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span></code></pre></div>
  2821. <div class="note">
  2822. <p>If you want to plug SCSS lint into your Grunt build process, you will be pleased to know there is a Grunt plugin for that called <a href="https://github.com/ahmednuaman/grunt-scss-lint">grunt-scss-lint</a>.</p>
  2823. <p>Also, if you are on the hunt for a neat application that works with SCSS-lint and the like, the guys at <a href="http://thoughtbot.com/">Thoughtbot</a> (Bourbon, Neat...) are working on <a href="https://houndci.com/">Hound</a>.</p>
  2824. </div>
  2825. <h6 id="further-reading-30">Further reading</h6>
  2826. <h1 id="too-long-didnt-read">Too Long; Didn’t read</h1>
  2827. <p>To sum up, we want:</p>
  2828. <ul>
  2829. <li>Two (2) spaces indents, no tabs;</li>
  2830. <li>80-characters wide lines;</li>
  2831. <li>Properly written multi-line CSS;</li>
  2832. <li>Meaningful use of whitespaces;</li>
  2833. <li>Quoted strings (single quotes) &amp; URLs;</li>
  2834. <li>No trailing 0, mandatory leading 0;</li>
  2835. <li>Calculations wrapped in parentheses;</li>
  2836. <li>No magic numbers;</li>
  2837. <li>Colors expressed in keywords &gt; HSL &gt; RGB &gt; hexadecimal;</li>
  2838. <li>Lists separated with commas;</li>
  2839. <li>No trailing comma in lists (since they are inlined);</li>
  2840. <li>Trailing comma in maps;</li>
  2841. <li>No selector nesting except for pseudo-classes and pseudo-elements;</li>
  2842. <li>Hyphen-delimited naming;</li>
  2843. <li>Extensive comments;</li>
  2844. <li>SassDoc-powered API comments;</li>
  2845. <li>Limited usage of <code>@extend</code>;</li>
  2846. <li>Simple mixins;</li>
  2847. <li>As few loops as possible, no <code>@while</code>;</li>
  2848. <li>Reduced number of dependencies;</li>
  2849. <li>Meaningful use of warnings and errors.</li>
  2850. </ul>
  2851. </article>
  2852. </section>
  2853. <nav id="jumpto">
  2854. <p>
  2855. <a href="/david/blog/">Accueil du blog</a> |
  2856. <a href="http://sass-guidelin.es/">Source originale</a> |
  2857. <a href="/david/stream/2019/">Accueil du flux</a>
  2858. </p>
  2859. </nav>
  2860. <footer>
  2861. <div>
  2862. <img src="/static/david/david-larlet-avatar.jpg" loading="lazy" class="avatar" width="200" height="200">
  2863. <p>
  2864. Bonjour/Hi!
  2865. Je suis <a href="/david/" title="Profil public">David&nbsp;Larlet</a>, je vis actuellement à Montréal et j’alimente cet espace depuis 15 ans. <br>
  2866. Si tu as apprécié cette lecture, n’hésite pas à poursuivre ton exploration. Par exemple via les <a href="/david/blog/" title="Expériences bienveillantes">réflexions bimestrielles</a>, la <a href="/david/stream/2019/" title="Pensées (dés)articulées">veille hebdomadaire</a> ou en t’abonnant au <a href="/david/log/" title="S’abonner aux publications via RSS">flux RSS</a> (<a href="/david/blog/2019/flux-rss/" title="Tiens c’est quoi un flux RSS ?">so 2005</a>).
  2867. </p>
  2868. <p>
  2869. Je m’intéresse à la place que je peux avoir dans ce monde. En tant qu’humain, en tant que membre d’une famille et en tant qu’associé d’une coopérative. De temps en temps, je fais aussi des <a href="https://github.com/davidbgk" title="Principalement sur Github mais aussi ailleurs">trucs techniques</a>. Et encore plus rarement, <a href="/david/talks/" title="En ce moment je laisse plutôt la place aux autres">j’en parle</a>.
  2870. </p>
  2871. <p>
  2872. Voici quelques articles choisis :
  2873. <a href="/david/blog/2019/faire-equipe/" title="Accéder à l’article complet">Faire équipe</a>,
  2874. <a href="/david/blog/2018/bivouac-automnal/" title="Accéder à l’article complet">Bivouac automnal</a>,
  2875. <a href="/david/blog/2018/commodite-effondrement/" title="Accéder à l’article complet">Commodité et effondrement</a>,
  2876. <a href="/david/blog/2017/donnees-communs/" title="Accéder à l’article complet">Des données aux communs</a>,
  2877. <a href="/david/blog/2016/accompagner-enfant/" title="Accéder à l’article complet">Accompagner un enfant</a>,
  2878. <a href="/david/blog/2016/senior-developer/" title="Accéder à l’article complet">Senior developer</a>,
  2879. <a href="/david/blog/2016/illusion-sociale/" title="Accéder à l’article complet">L’illusion sociale</a>,
  2880. <a href="/david/blog/2016/instantane-scopyleft/" title="Accéder à l’article complet">Instantané Scopyleft</a>,
  2881. <a href="/david/blog/2016/enseigner-web/" title="Accéder à l’article complet">Enseigner le Web</a>,
  2882. <a href="/david/blog/2016/simplicite-defaut/" title="Accéder à l’article complet">Simplicité par défaut</a>,
  2883. <a href="/david/blog/2016/minimalisme-esthetique/" title="Accéder à l’article complet">Minimalisme et esthétique</a>,
  2884. <a href="/david/blog/2014/un-web-omni-present/" title="Accéder à l’article complet">Un web omni-présent</a>,
  2885. <a href="/david/blog/2014/manifeste-developpeur/" title="Accéder à l’article complet">Manifeste de développeur</a>,
  2886. <a href="/david/blog/2013/confort-convivialite/" title="Accéder à l’article complet">Confort et convivialité</a>,
  2887. <a href="/david/blog/2013/testament-numerique/" title="Accéder à l’article complet">Testament numérique</a>,
  2888. et <a href="/david/blog/" title="Accéder aux archives">bien d’autres…</a>
  2889. </p>
  2890. <p>
  2891. On peut <a href="mailto:david%40larlet.fr" title="Envoyer un courriel">échanger par courriel</a>. Si éventuellement tu souhaites que l’on travaille ensemble, tu devrais commencer par consulter le <a href="http://larlet.com">profil dédié à mon activité professionnelle</a> et/ou contacter directement <a href="http://scopyleft.fr/">scopyleft</a>, la <abbr title="Société coopérative et participative">SCOP</abbr> dont je fais partie depuis six ans. Je recommande au préalable de lire <a href="/david/blog/2018/cout-site/" title="Attention ce qui va suivre peut vous choquer">combien coûte un site</a> et pourquoi je suis plutôt favorable à une <a href="/david/pro/devis/" title="Discutons-en !">non-demande de devis</a>.
  2892. </p>
  2893. <p>
  2894. Je ne traque pas ta navigation mais mon
  2895. <abbr title="Alwaysdata, 62 rue Tiquetonne 75002 Paris, +33.184162340">hébergeur</abbr>
  2896. conserve des logs d’accès.
  2897. </p>
  2898. </div>
  2899. </footer>
  2900. <script type="text/javascript">
  2901. ;(_ => {
  2902. const jumper = document.getElementById('jumper')
  2903. jumper.addEventListener('click', e => {
  2904. e.preventDefault()
  2905. const anchor = e.target.getAttribute('href')
  2906. const targetEl = document.getElementById(anchor.substring(1))
  2907. targetEl.scrollIntoView({behavior: 'smooth'})
  2908. })
  2909. })()
  2910. </script>