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; } }

[SCSS] Loop Over Data with the SCSS @each Control Directive的更多相关文章

  1. [SCSS] Write similar classes with the SCSS @for Control Directive

    Writing similar classes with minor variations, like utility classes, can be a pain to write and upda ...

  2. [SCSS] Write Custom Functions with the SCSS @function Directive

    Writing SCSS @functions is similar to writing functions in other programming languages; they can acc ...

  3. vue,一路走来(17)--vue使用scss,并且全局引入公共scss样式

    最近朋友问如何在vue项目中使用scss样式,想起之前项目是直接在main.js直接import css文件的,然而main.js不可以直接import scss文件. import './asset ...

  4. 在vue-cli中安装scss,且可以全局引入scss的步骤

    简历魔板__个人简历模板在线生成 在写vue的css样式时,觉得需要css预处理器让自己的css更加简洁.适应性更强.可读性更佳,更易于代码的维护,于是在vue-cli脚手架采用scss.写过的人都知 ...

  5. csharp: Data binding in WPF DataGrid control

    <Window x:Class="WpfProjectDemo.MainWindow" xmlns="http://schemas.microsoft.com/wi ...

  6. VueCli3如何传递scss全局变量

    当我们尝试在一个scss文件中定义全局变量然后在.vue文件中使用的时候 哦豁,找不到变量,意料之外 我发现犯了一个错误,没导入,@import 'path/to/file.scss',不过这样的话, ...

  7. Nuxt.js中scss公用文件(不使用官方插件style-resources)

    项目多多少少应该都遇到有公用文件这种情况,比如说偶尔某一天产品来找你,能不能明天把网站的这个颜色给我改下?第二天再来给我换回来? 如果再css2.x时代,不使用css预处理技术,这一改只能“查找替换” ...

  8. vue cli 3

    介绍 Vue CLI 是一个基于 Vue.js 进行快速开发的完整系统 通过 @vue/cli 搭建交互式的项目脚手架. 通过 @vue/cli + @vue/cli-service-global 快 ...

  9. d2-admin中那些不错的技巧

    d2-admin基于vue-cli3 路由相关 刷新路由,参照官方  组件内的守卫 但是搞不明白为何加了句 render:h => h() { path: 'refresh', name: 'r ...

随机推荐

  1. opencv标定程序(改动)

    转载请注明来自:http://blog.csdn.net/zhouyelihua/article/details/38421377 资源下载见:点击打开链接 百度云盘免积分下载:https://pan ...

  2. linux 批量设置文件夹755 文件644权限

    linux 批量设置文件夹755 文件644权限 文件来源 http://www.111cn.net/sys/linux/109724.htm 本文章来为各位介绍一篇关于linux 批量设置文件夹75 ...

  3. less中混合

    @charset "UTF-8"; //1 普通混合 //2 不带输出的混合:加() .font_hx(){ font-size: 28px; color: red; } h1{ ...

  4. golang pipe

    ===============golang pipe============== package main import ( "fmt" "io" ) func ...

  5. 原生js大总结七

    061.如何获取父级节点.上一个子级节点.下一个子级节点    nextElementSibling  后一个兄弟元素  (如果没有是null)    previousElementSibling   ...

  6. 为什么出现ORM

    ORM(Object Relational Mapping)对象关系映射,是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术 . 为什么出现ORM? 面向对象的特征:我们通常使用的开发语言J ...

  7. BZOJ——T2190: [SDOI2008]仪仗队

    Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 3216  Solved: 2075[Submit][Status][Discuss] http://w ...

  8. 常用的织梦dedecms安全设置集合整理

    织梦系统用户很多,被发现的漏洞也就相对很多,所以网站安全需要做好,很多所谓的“黑客”都是用工具来扫描入侵,厉害点的人是不屑来黑我们的小网站的,所以在我们不是专业维护人员情况下,做好一般的安全防护就可以 ...

  9. C++卷积神经网络实例:tiny_cnn代码具体解释(8)——partial_connected_layer层结构类分析(上)

    在之前的博文中我们已经将顶层的网络结构都介绍完毕,包括卷积层.下採样层.全连接层,在这篇博文中主要有两个任务.一是总体贯通一下卷积神经网络在对图像进行卷积处理的整个流程,二是继续我们的类分析.这次须要 ...

  10. vim编辑器经常使用命令

    高级一些的编辑器,都会包括宏功能,vim当然不能缺少了.在vim中使用宏是很方便的: :qx     開始记录宏,并将结果存入寄存器xq     退出记录模式@x     播放记录在x寄存器中的宏命令 ...