当前位置: 首页 > news >正文

Sass 最基础的语法

把每个点最简单的部分记录一下,方便自己查找

官方文档链接

Sass 笔记

  • 1. `&` 父选择器,编译后为父选择器
  • 2. `:` 嵌套属性
  • 3. `$` 变量
    • 3.1 数据类型
    • 3.2 变量赋值
    • 3.3. 数组
    • 3.4. map
  • 4. 算数运算符
  • 5. `#{}`插值语法
    • 5.1 可以在选择器或属性名中使用变量
    • 5.2 将有引号的字符串编译为无引号
  • 6. @import
  • 7. @media
  • 8. @extend : 延申(感觉像继承)
  • 9. 控制指令
    • 9.1 `@if` `@else if` `@else`
    • 9.2 `@for`
    • 9.3 `@each`
      • 9.3.1 遍历一维数组
      • 9.3.2 遍历`map<key : value>`
      • 9.3.3 遍历二维数组
    • 9.4 `@while`
  • 10 @mixin 混合指令
    • 10.1 定义样式并引用
    • 10.2 带参数的混合,并且有默认值
  • 11. `@function` 函数指令 `@return` 返回

1. & 父选择器,编译后为父选择器

a {font-weight: bold;text-decoration: none;&:hover { text-decoration: underline; }body.firefox & { font-weight: normal; }
}

编译为

a {font-weight: bold;text-decoration: none; }a:hover {text-decoration: underline; }body.firefox a {font-weight: normal; }

2. : 嵌套属性

.funky {font: 20px/24px {family: fantasy;weight: bold;}
}

编译为

.funky {font: 20px/24px;font-family: fantasy;font-weight: bold; }

3. $ 变量

#main {$width: 5em !global;  // !global:声明为全局变量,可在作用域外使用width: $width;
}
#sidebar {width: $width;
}

编译为

#main {width: 5em;
}
#sidebar {width: 5em;
}

3.1 数据类型

  • 数字,1, 2, 13, 10px
  • 字符串,有引号字符串与无引号字符串,"foo", 'bar', baz
  • 颜色,blue, #04a3f9, rgba(255,0,0,0.5)
  • 布尔型,true, false
  • 空值,null
  • 数组 (list),用空格或逗号作分隔符,1.5em 1em 0 2em, Helvetica, Arial, sans-serif
  • maps, 相当于 JavaScript 的 object,(key1: value1, key2: value2)

3.2 变量赋值

$i: 6;
$i: $i - 2;
$name: jack;

3.3. 数组

数组之间的元素可以用,隔开,也可以不用

margin: 10px 15px 0 0 
font-face: Helvetica, Arial, sans-serif

nth 函数可以直接访问数组中的某一项;
join 函数可以将多个数组连接在一起;
append 函数可以在数组中添加新值;
@each 指令能够遍历数组中的每一项。

3.4. map

(key1 : value1,key2 : value2)

4. 算数运算符

  1. + - * /
  2. > < > = <= == !=
  3. /有两个作用:除法,分隔数字,具体怎么用看文档
  4. +也用作字符串连接,计算结果以+左侧的字符串为准
+左侧+右侧连接后
有引号有引号有引号
无引号无引号无引号
有引号无引号有引号
无引号有引号无引号

5. #{}插值语法

5.1 可以在选择器或属性名中使用变量

$name: foo;
$attr: border;
p.#{$name} {#{$attr}-color: blue;
}

编译为

p.foo {border-color: blue; }

5.2 将有引号的字符串编译为无引号

@mixin firefox-message($selector) {body.firefox #{$selector}:before {content: "Hi, Firefox users!";}
}
@include firefox-message(".header");

编译为

body.firefox .header:before {content: "Hi, Firefox users!"; }

6. @import

  1. 导入的是scss文件可以只写文件名:@import ‘foo’
  2. 在vue中使用一般情况:@import url(../xxxx/xxx.css)
  3. 可以在嵌套进css中使用,这样引入的内容就只能在引入的局部使用

7. @media

8. @extend : 延申(感觉像继承)

属性重复,谁在后面执行谁有优先权

.error {border: 1px #f00;background-color: #fdd;
}
.seriousError {@extend .error;border-width: 3px;
}

编译后

.error .seriousError{border: 1px #f00;background-color: #fdd;
}
.seriousError {border-width: 3px;
}

9. 控制指令

9.1 @if @else if @else

$type: monster;
p {@if $type == ocean {color: blue;} @else if $type == matador {color: red;} @else if $type == monster {color: green;} @else {color: black;}
}

编译后

p{color: green
}

9.2 @for

@for $var from <start> through <end> 包含start和end的值
@for $var from <start> to <end> 不包含start的值,包含end的值

@for $i from 1through 3 {.item-#{$i} { width : 2em * $i }
}

编译后

.item-1 { width: 2em }
.item-2 { width: 4em }
.itme-3 { width: 6em }

9.3 @each

@each $var in <list> list可以是一连串的字符串、数组、map

9.3.1 遍历一维数组

@each $animal in puma, sea-slug, etret, salamander {.#{$animal}-icon{background-image: url('/images/#{$animal}.png');}
}

编译后

.puma-icon {  background-image: url('/images/puma.png'); }
.sea-slug-icon { background-image: url('/images/sea-slug-icon.png'); }
.etret-icon { background-image: url('/images/etret.png'); }
.salamander-icon { background-image: url('/images/salamander.png'); }

9.3.2 遍历map<key : value>

@each $header, $size in (h1: 2em, h2: 1.5em, h3: 1.2em) {#{$header} {font-size: $size;}
}

编译后

h1 {font-size: 2em; }
h2 {font-size: 1.5em; }
h3 {font-size: 1.2em; }

9.3.3 遍历二维数组

@each $animal, $color, $cursor in (puma, black, default),(sea-slug, blue, pointer),(egret, white, move) {.#{$animal}-icon {background-image: url('/images/#{$animal}.png');border: 2px solid $color;cursor: $cursor;}
}

编译后

.puma-icon {background-image: url('/images/puma.png');border: 2px solid black;cursor: default; }
.sea-slug-icon {background-image: url('/images/sea-slug.png');border: 2px solid blue;cursor: pointer; }
.egret-icon {background-image: url('/images/egret.png');border: 2px solid white;cursor: move; }

9.4 @while

$i: 6;
@while $i > 0 {.item-#{$i} { width: 2em * $i; }$i: $i - 2;
}

编译后

.item-6 {width: 12em; }.item-4 {width: 8em; }.item-2 {width: 4em; }

10 @mixin 混合指令

@mixin 像定义只是存放数据的函数,但是必须用@include调用

10.1 定义样式并引用

  1. 定义,(font:使用了嵌套属性)
@mixin large-text {font: {family: Arial;size: 20px;weight: bold;}color: #ff0000;
}
  1. 在语句内引用
.page-title {@include large-text;.padding: 4px;margin-top: 10px;
}
  1. 编译后
.page-title {font-family: Arial;font-size: 20px;font-weight: bold;color: #ff0000;padding: 4px;margin-top: 10px; }
  • 如果在最外层调用,没有其他语句包裹
@mixin silly-links {a {color: blue;background-color: red;}
}
@include silly-links;

编译后

  a {color: blue;background-color: red;}

10.2 带参数的混合,并且有默认值

@mixin sexy-border($color, $width: 1in) {border: {color: $color;width: $width;style: dashed;}
}p { @include sexy-border(blue); }
或者
p { @include sexy-border($color: blue); }

编译后

p{border-color: blue;border-width: 1in;border-style: dashed;
}

11. @function 函数指令 @return 返回

$grid-width: 40px;
$gutter-width: 10px;@function grid-width($n) {@return $n * $grid-width + ($n - 1) * $gutter-width;
}#sidebar { width: grid-width(5); }

编译为

#sidebar {width: 240px; }

相关文章:

Sass 最基础的语法

把每个点最简单的部分记录一下&#xff0c;方便自己查找 官方文档链接 Sass 笔记 1. & 父选择器&#xff0c;编译后为父选择器2. : 嵌套属性3. $ 变量3.1 数据类型3.2 变量赋值3.3. 数组3.4. map 4. 算数运算符5. #{}插值语法5.1 可以在选择器或属性名中使用变量5.2 将有引…...

2023年11月数据库流行度最新排名

点击查看最新数据库流行度最新排名&#xff08;每月更新&#xff09; 2023年11月数据库流行度最新排名 TOP DB顶级数据库索引是通过分析在谷歌上搜索数据库名称的频率来创建的 一个数据库被搜索的次数越多&#xff0c;这个数据库就被认为越受欢迎。这是一个领先指标。原始数…...

JavaEE-部署项目到服务器

本部分内容为&#xff1a;安装依赖&#xff1a;JDK&#xff0c;Tomcat&#xff0c;Mysql&#xff1b;部署项目到服务器 什么是Tomcat Tomcat简单的说就是一个运行JAVA的网络服务器&#xff0c;底层是Socket的一个程序&#xff0c;它也是JSP和Serlvet的一个容器。 为什么我们需要…...

计算机网络期末复习-Part1

1、列举几种接入网技术&#xff1a;ADSL&#xff0c;HFC&#xff0c;FTTH&#xff0c;LAN&#xff0c;WLAN ADSL&#xff08;Asymmetric Digital Subscriber Line&#xff09;&#xff1a;非对称数字用户线路。ADSL 是一种用于通过电话线连接到互联网的技术&#xff0c;它提供…...

Redis系列-Redis过期策略以及内存淘汰机制【6】

目录 Redis系列-Redis过期策略以及内存淘汰机制【6】redis过期策略内存淘汰机制算法LRU算法LFU 其他场景对过期key的处理FAQ为什么不用定时删除策略? Ref 个人主页: 【⭐️个人主页】 需要您的【&#x1f496; 点赞关注】支持 &#x1f4af; Redis系列-Redis过期策略以及内存淘…...

多语言翻译软件 Mate Translate mac中文版特色功能

Mate Translate for Mac是一款多语言翻译软件&#xff0c;Mate Translate mac可以帮你翻译超过100种语言的单词和短语&#xff0c;使用文本到语音转换&#xff0c;并浏览历史上已经完成的翻译。你还可以使用Control S在弹出窗口中快速交换语言。 Mate Translate Mac版特色功能…...

Python GUI标准库tkinter实现与记事本相同菜单的文本编辑器(一)

介绍&#xff1a; Windows操作系统中自带了一款记事本应用程序&#xff0c;通常用于记录文字信息&#xff0c;具有简单文本编辑功能。Windows的记事本可以新建、打开、保存文件&#xff0c;有复制、粘贴、删除等功能&#xff0c;还可以设置字体类型、格式和查看日期时间等。 …...

Decimal.ToString()堆栈溢出异常

Decimal.ToString() 堆栈溢出异常 导致以下报错: A process serving application pool XXX suffered a fatal communication error with the Windows Process Activation Service. The process id was 7132. The data field contains the error number. Application pool …...

com.genuitec.eclipse.springframework.springnature

Your IDE is missing natures to properly support your projects. Some extensions on the eclipse marketplace can be installed to support those natures. com.genuitec.eclipse.springframework.springnature 移除 <nature>om.genuitec.eclipse.springframework.…...

wangeditor富文本编辑器的使用(vue)

官网 官方demo 参考 安装 yarn add wangeditor/editor yarn add wangeditor/editor-for-vue 封装的富文本组件 <template><div style"border: 1px solid #ccc"><Toolbarstyle"border-bottom: 1px solid #ccc":editor"editorRef"…...

物联网水表有什么弊端吗?

物联网水表作为新一代智能水表&#xff0c;虽然在很大程度上提高了水资源的管理效率&#xff0c;但也存在一定的弊端。在这篇文章中&#xff0c;我们将详细讨论物联网水表的弊端&#xff0c;以帮助大家更全面地了解这一技术。 一、安全隐患 1.数据泄露&#xff1a;物联网水表通…...

安卓 车轮视图 WheelView kotlin

安卓 车轮视图 WheelView kotlin 前言一、代码解析1.初始化2.初始化数据3.onMeasure4.onDraw5.onTouchEvent6.其他 6.ItemObject二、完整代码总结 前言 有个需求涉及到类似这个视图&#xff0c;于是在网上找了个轮子&#xff0c;自己改吧改吧用&#xff0c;拿来主义当然后&…...

升级Redisson版本兼容问题

升级版本&#xff1a;从 3.10.6 升级到3.18.0 报错: java.io.IOException: Unsupported protocol version 252 java.io.IOException: Unsupported protocol version 252at org.jboss.marshalling.river.RiverUnmarshaller.start(RiverUnmarshaller.java:1375)at org.redisson…...

前端框架Bootstrap

前端框架Bootstrap 该框架已经帮我们写好了很多页面样式&#xff0c;如果需要使用&#xff0c;只需要下载对应文件 直接CV拷贝即可 在使用Bootstrap的时候&#xff0c;所有的页面样式只需要通过修改class属性来调节即可 什么是Bootstrap Bootstrap是一个开源的前端框架…...

Flink SQL TopN语句详解

TopN 定义&#xff08;⽀持 Batch\Streaming&#xff09;&#xff1a; TopN 对应离线数仓的 row_number()&#xff0c;使⽤ row_number() 对某⼀个分组的数据进⾏排序。 应⽤场景&#xff1a; 根据 某个排序 条件&#xff0c;计算 某个分组 下的排⾏榜数据。 SQL 语法标准&am…...

k8s之数据卷

一&#xff0c;存储卷 容器磁盘上的文件的生命周期是短暂的&#xff0c;这就使得在容器中运行重要应用时会出现一些问题。首先&#xff0c;当容器崩溃时&#xff0c;kubelet 会重启它&#xff0c;但是容器中的文件将丢失——容器以干净的状态&#xff08;镜像最初的状态&#…...

服务器网络

配置 通常使用ping查看网络 如果能ping通&#xff0c;不能ssh登陆&#xff0c;安装 sudo apt update sudo apt install openssh-server如果已经安装&#xff0c;查看防火墙状态&#xff0c;inactive(不活跃) sudo ufw status sudo ufw allow ssh sudo ufw reload查看ssh状态 s…...

YOLOv8-seg 分割代码详解(一)Predict

前言 本文从 U-Net 入手熟悉分割的简单方法&#xff0c;再看 YOLOv8 的方法。主要梳理 YOLOv8 的网络结构&#xff0c;以及 Predict 过程的后处理方法。 U-Net 代码地址&#xff1a;https://github.com/milesial/Pytorch-UNet YOLOv8 代码地址&#xff1a;https://github.com/…...

Docker学习——④

文章目录 1、Docker Image&#xff08;镜像&#xff09;2、镜像命令详解2.1 docker rmi2.2 docker save2.3 docker load2.4 docker image inspect2.5 docker history2.6 docker image prune 3、镜像综合实战3.1 离线镜像迁移3.2 镜像存储的压缩与共享 1、Docker Image&#xff…...

Android选项卡TabHost

选项卡主要由TabHost(标签&#xff0c;主人)&#xff0c;TabWidget(微件)和FrameLayout3个组件组成&#xff0c;用于实现一个多标签页的用户界面。 1. TabHost在XML文件中添加&#xff1a; XML布局文件中添加选项卡时必须使用系统id来为各组件指定id属性。 <TabHostandro…...

STM32+rt-thread判断是否联网

一、根据NETDEV_FLAG_INTERNET_UP位判断 static bool is_conncected(void) {struct netdev *dev RT_NULL;dev netdev_get_first_by_flags(NETDEV_FLAG_INTERNET_UP);if (dev RT_NULL){printf("wait netdev internet up...");return false;}else{printf("loc…...

线程与协程

1. 线程与协程 1.1. “函数调用级别”的切换、上下文切换 1. 函数调用级别的切换 “函数调用级别的切换”是指&#xff1a;像函数调用/返回一样轻量地完成任务切换。 举例说明&#xff1a; 当你在程序中写一个函数调用&#xff1a; funcA() 然后 funcA 执行完后返回&…...

蓝桥杯 2024 15届国赛 A组 儿童节快乐

P10576 [蓝桥杯 2024 国 A] 儿童节快乐 题目描述 五彩斑斓的气球在蓝天下悠然飘荡&#xff0c;轻快的音乐在耳边持续回荡&#xff0c;小朋友们手牵着手一同畅快欢笑。在这样一片安乐祥和的氛围下&#xff0c;六一来了。 今天是六一儿童节&#xff0c;小蓝老师为了让大家在节…...

鸿蒙中用HarmonyOS SDK应用服务 HarmonyOS5开发一个医院挂号小程序

一、开发准备 ​​环境搭建​​&#xff1a; 安装DevEco Studio 3.0或更高版本配置HarmonyOS SDK申请开发者账号 ​​项目创建​​&#xff1a; File > New > Create Project > Application (选择"Empty Ability") 二、核心功能实现 1. 医院科室展示 /…...

【CSS position 属性】static、relative、fixed、absolute 、sticky详细介绍,多层嵌套定位示例

文章目录 ★ position 的五种类型及基本用法 ★ 一、position 属性概述 二、position 的五种类型详解(初学者版) 1. static(默认值) 2. relative(相对定位) 3. absolute(绝对定位) 4. fixed(固定定位) 5. sticky(粘性定位) 三、定位元素的层级关系(z-i…...

什么?连接服务器也能可视化显示界面?:基于X11 Forwarding + CentOS + MobaXterm实战指南

文章目录 什么是X11?环境准备实战步骤1️⃣ 服务器端配置(CentOS)2️⃣ 客户端配置(MobaXterm)3️⃣ 验证X11 Forwarding4️⃣ 运行自定义GUI程序(Python示例)5️⃣ 成功效果![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/55aefaea8a9f477e86d065227851fe3d.pn…...

BLEU评分:机器翻译质量评估的黄金标准

BLEU评分&#xff1a;机器翻译质量评估的黄金标准 1. 引言 在自然语言处理(NLP)领域&#xff0c;衡量一个机器翻译模型的性能至关重要。BLEU (Bilingual Evaluation Understudy) 作为一种自动化评估指标&#xff0c;自2002年由IBM的Kishore Papineni等人提出以来&#xff0c;…...

libfmt: 现代C++的格式化工具库介绍与酷炫功能

libfmt: 现代C的格式化工具库介绍与酷炫功能 libfmt 是一个开源的C格式化库&#xff0c;提供了高效、安全的文本格式化功能&#xff0c;是C20中引入的std::format的基础实现。它比传统的printf和iostream更安全、更灵活、性能更好。 基本介绍 主要特点 类型安全&#xff1a…...

如何配置一个sql server使得其它用户可以通过excel odbc获取数据

要让其他用户通过 Excel 使用 ODBC 连接到 SQL Server 获取数据&#xff0c;你需要完成以下配置步骤&#xff1a; ✅ 一、在 SQL Server 端配置&#xff08;服务器设置&#xff09; 1. 启用 TCP/IP 协议 打开 “SQL Server 配置管理器”。导航到&#xff1a;SQL Server 网络配…...

shell脚本质数判断

shell脚本质数判断 shell输入一个正整数,判断是否为质数(素数&#xff09;shell求1-100内的质数shell求给定数组输出其中的质数 shell输入一个正整数,判断是否为质数(素数&#xff09; 思路&#xff1a; 1:1 2:1 2 3:1 2 3 4:1 2 3 4 5:1 2 3 4 5-------> 3:2 4:2 3 5:2 3…...