当前位置: 首页 > 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…...

龙虎榜——20250610

上证指数放量收阴线&#xff0c;个股多数下跌&#xff0c;盘中受消息影响大幅波动。 深证指数放量收阴线形成顶分型&#xff0c;指数短线有调整的需求&#xff0c;大概需要一两天。 2025年6月10日龙虎榜行业方向分析 1. 金融科技 代表标的&#xff1a;御银股份、雄帝科技 驱动…...

【人工智能】神经网络的优化器optimizer(二):Adagrad自适应学习率优化器

一.自适应梯度算法Adagrad概述 Adagrad&#xff08;Adaptive Gradient Algorithm&#xff09;是一种自适应学习率的优化算法&#xff0c;由Duchi等人在2011年提出。其核心思想是针对不同参数自动调整学习率&#xff0c;适合处理稀疏数据和不同参数梯度差异较大的场景。Adagrad通…...

Xshell远程连接Kali(默认 | 私钥)Note版

前言:xshell远程连接&#xff0c;私钥连接和常规默认连接 任务一 开启ssh服务 service ssh status //查看ssh服务状态 service ssh start //开启ssh服务 update-rc.d ssh enable //开启自启动ssh服务 任务二 修改配置文件 vi /etc/ssh/ssh_config //第一…...

Mybatis逆向工程,动态创建实体类、条件扩展类、Mapper接口、Mapper.xml映射文件

今天呢&#xff0c;博主的学习进度也是步入了Java Mybatis 框架&#xff0c;目前正在逐步杨帆旗航。 那么接下来就给大家出一期有关 Mybatis 逆向工程的教学&#xff0c;希望能对大家有所帮助&#xff0c;也特别欢迎大家指点不足之处&#xff0c;小生很乐意接受正确的建议&…...

vue3 定时器-定义全局方法 vue+ts

1.创建ts文件 路径&#xff1a;src/utils/timer.ts 完整代码&#xff1a; import { onUnmounted } from vuetype TimerCallback (...args: any[]) > voidexport function useGlobalTimer() {const timers: Map<number, NodeJS.Timeout> new Map()// 创建定时器con…...

Caliper 配置文件解析:config.yaml

Caliper 是一个区块链性能基准测试工具,用于评估不同区块链平台的性能。下面我将详细解释你提供的 fisco-bcos.json 文件结构,并说明它与 config.yaml 文件的关系。 fisco-bcos.json 文件解析 这个文件是针对 FISCO-BCOS 区块链网络的 Caliper 配置文件,主要包含以下几个部…...

基于TurtleBot3在Gazebo地图实现机器人远程控制

1. TurtleBot3环境配置 # 下载TurtleBot3核心包 mkdir -p ~/catkin_ws/src cd ~/catkin_ws/src git clone -b noetic-devel https://github.com/ROBOTIS-GIT/turtlebot3.git git clone -b noetic https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git git clone -b noetic-dev…...

Linux 内存管理实战精讲:核心原理与面试常考点全解析

Linux 内存管理实战精讲&#xff1a;核心原理与面试常考点全解析 Linux 内核内存管理是系统设计中最复杂但也最核心的模块之一。它不仅支撑着虚拟内存机制、物理内存分配、进程隔离与资源复用&#xff0c;还直接决定系统运行的性能与稳定性。无论你是嵌入式开发者、内核调试工…...

vulnyx Blogger writeup

信息收集 arp-scan nmap 获取userFlag 上web看看 一个默认的页面&#xff0c;gobuster扫一下目录 可以看到扫出的目录中得到了一个有价值的目录/wordpress&#xff0c;说明目标所使用的cms是wordpress&#xff0c;访问http://192.168.43.213/wordpress/然后查看源码能看到 这…...

Qt 事件处理中 return 的深入解析

Qt 事件处理中 return 的深入解析 在 Qt 事件处理中&#xff0c;return 语句的使用是另一个关键概念&#xff0c;它与 event->accept()/event->ignore() 密切相关但作用不同。让我们详细分析一下它们之间的关系和工作原理。 核心区别&#xff1a;不同层级的事件处理 方…...