[SCSS] Loop Over Data with the SCSS @each Control Directive
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的更多相关文章
- [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 ...
- [SCSS] Write Custom Functions with the SCSS @function Directive
Writing SCSS @functions is similar to writing functions in other programming languages; they can acc ...
- vue,一路走来(17)--vue使用scss,并且全局引入公共scss样式
最近朋友问如何在vue项目中使用scss样式,想起之前项目是直接在main.js直接import css文件的,然而main.js不可以直接import scss文件. import './asset ...
- 在vue-cli中安装scss,且可以全局引入scss的步骤
简历魔板__个人简历模板在线生成 在写vue的css样式时,觉得需要css预处理器让自己的css更加简洁.适应性更强.可读性更佳,更易于代码的维护,于是在vue-cli脚手架采用scss.写过的人都知 ...
- csharp: Data binding in WPF DataGrid control
<Window x:Class="WpfProjectDemo.MainWindow" xmlns="http://schemas.microsoft.com/wi ...
- VueCli3如何传递scss全局变量
当我们尝试在一个scss文件中定义全局变量然后在.vue文件中使用的时候 哦豁,找不到变量,意料之外 我发现犯了一个错误,没导入,@import 'path/to/file.scss',不过这样的话, ...
- Nuxt.js中scss公用文件(不使用官方插件style-resources)
项目多多少少应该都遇到有公用文件这种情况,比如说偶尔某一天产品来找你,能不能明天把网站的这个颜色给我改下?第二天再来给我换回来? 如果再css2.x时代,不使用css预处理技术,这一改只能“查找替换” ...
- vue cli 3
介绍 Vue CLI 是一个基于 Vue.js 进行快速开发的完整系统 通过 @vue/cli 搭建交互式的项目脚手架. 通过 @vue/cli + @vue/cli-service-global 快 ...
- d2-admin中那些不错的技巧
d2-admin基于vue-cli3 路由相关 刷新路由,参照官方 组件内的守卫 但是搞不明白为何加了句 render:h => h() { path: 'refresh', name: 'r ...
随机推荐
- Android之——短信的备份与还原
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/47091281 眼下,Android手机中的一些软件能够实现手机短信的备份与还原操作 ...
- actionBar-双行字体大小修改
<style name="BackupRestore.Theme.Person" parent="@style/BackupRestore.Theme"& ...
- vue踩坑记-在项目中安装依赖模块npm install报错
在维护别人的项目的时候,在项目文件夹中安装npm install模块的时候,报错如下: npm ERR! path D:\ShopApp\node_modules\fsevents\node_modu ...
- <link rel="shortcut icon" href="Xubuntu.ico" type="image/x-icon" /> <LINK href="Xubuntu.ico" rel="shortcut icon"> <link href="Xubuntu.ico" rel="B
<link rel="shortcut icon" href="Xubuntu.ico" type="image/x-icon" /& ...
- HttpClient的基本使用
HttpClient的基本使用 前言 HttpClient是Apache提供的一个用于在Java中处理HTTP请求.响应操作的工具,由于JDK自带的API对HTTP协议的支持不是很友好,使用起来也不是 ...
- ArcGIS Engine 线段绘制
转自ArcGIS Engine 线段绘制研究 基本步骤 构建形状 1. 创建 IPoint IPoint m_Point = new PointClass(); m_Point.PutCoords(x ...
- asp.net Code学习二(使用vs 2015 update 3)
1.在vs 2015上搭建asp.net core: 安装 .Net core sdk.vs2015 tool 即可使用vs 2015开发asp.net core. 2.Net core中国学习小组 ...
- C# 依据KeyEventArgs与组合键字符串相互转换
/// 快捷键相关的类 /// </summary> public static class HotKeyInfo { /// <summary> /// 依据KeyEvent ...
- 7.zookeeper集群搭建(windows环境下)
转自:https://www.cnblogs.com/xuxiuxiu/p/5868481.html 本次zk测试部署版本为3.4.6版本,下载地址http://mirrors.cnnic.cn/ap ...
- selenium 自动化基础知识(各种定位)
元素的定位 webdriver 提供了一很多对象定位方法 例如: [ id ] , name , class name , link text , partial link text , tag n ...