博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[SCSS] Loop Over Data with the SCSS @each Control Directive
阅读量:5256 次
发布时间:2019-06-14

本文共 2071 字,大约阅读时间需要 6 分钟。

The SCSS @for directive is great when we know how many iterations are required and we only need 1 variable. What if we need multiple variables to iterate over data sets? Hello SCSS maps and the @each control directive! In this lesson, we’ll check out iterating with lists and looping over data sets with maps and the @each directive.

 

// work with simple array$superheroes: wonder-woman, spiderman, batman, superman;@each $hero in $superheroes {  .#{$hero}-logo {    content: "#{$hero}";  }}// we get.wonder-woman-logo {  content: "wonder-woman"; }.spiderman-logo {  content: "spiderman"; }.batman-logo {  content: "batman"; }.superman-logo {  content: "superman"; }

 

key: value pairs using map-get():

// work with key: value pair$breakpoints: (sm: 375px, md: 768px, lg: 1200px);$container-widths: (sm: 250px, md: 500px, lg: 750px);@each $size, $bp in $breakpoints {  @media only screen and (min-width: $bp) {    .container-width {      // because $breakpoints and $container-widths have the same key      // we can use map_get(target_ary, key) to get value      width: map_get($container-widths, $size);    }  }}// we get@media only screen and (min-width: 375px) {  .container-width {    width: 250px; } }@media only screen and (min-width: 768px) {  .container-width {    width: 500px; } }@media only screen and (min-width: 1200px) {  .container-width {    width: 750px; } }

 

index: values pair using nth()

$hero-media:  (1 375px 768px crimson),              (2 768px 1000px darkred),              (3 1200px 1400px grey),              (4 768px 1200px blue);// we get@media only screen and (min-width: 375px) and (max-width: 768px) {  .wonder-woman {    background-color: crimson; } }@media only screen and (min-width: 768px) and (max-width: 1000px) {  .spiderman {    background-color: darkred; } }@media only screen and (min-width: 1200px) and (max-width: 1400px) {  .batman {    background-color: grey; } }@media only screen and (min-width: 768px) and (max-width: 1200px) {  .superman {    background-color: blue; } }

 

转载于:https://www.cnblogs.com/Answer1215/p/6873635.html

你可能感兴趣的文章
Dubbo入门
查看>>
The laser engraving machine requires little knowledge
查看>>
通过反射获取java nio Direct Memory 的最大值和已使用值
查看>>
singleton单例模式小结
查看>>
Linux-(vmstat,iostat,netstat)
查看>>
使用IntelliJ IDEA 配置Maven(入门)
查看>>
你会用C#压缩access数据库吗?xuedaonet教你如何用C#压缩access数据库?
查看>>
C++ 一些常用函数的使用(1)
查看>>
求第K大的问题
查看>>
[Leetcode] Binary Tree Zigzag Level Order Traversal
查看>>
[C++] c++中二进制文件的创建与使用
查看>>
C#脚本引擎 CS-Script 之(一)——初识
查看>>
codeforces742B
查看>>
codeforces645B
查看>>
The second curriculum design experiment report in spring 2019
查看>>
Java内存模型
查看>>
jms的初步认识
查看>>
项目管理之路(1):初步踏入项目管理
查看>>
机顶盒webview开发调试
查看>>
js中的arguments
查看>>