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

css/scss(at-rules)基础使用(basic use)

css 

1.媒体查询(media search)

根据设备特性(如屏幕宽度)应用不同样式:

apply different styles depending on device characteristics,such as screen width

@media (max-width: 600px) {
  .box { background: red; }
}

 2.@keyframes(动画关键帧)(Animation key frame)

定义 CSS 动画的关键帧:

difine key frame of css animation

@keyframes slide {
  0% { transform: translateX(0); }
  100% { transform: translateX(100px); }
}

 3.@font-face(自定义字体)(custom font)

引入自定义字体文件:

introduce define font file

@font-face {
  font-family: 'MyFont';
  src: url('myfont.woff2') format('woff2');
}

 4.@supports(特性检测)(feature detection)

根据浏览器支持的特性应用样式:

apply styles based on features supported by your brower 

@supports (display: grid) {
  .container { display: grid; }
}

 5.@import(导入外部 CSS)(inporting external css file)

@import url('reset.css');

scss

1. 变量(Variables)

作用:用 $ 定义变量,存储颜色、字体等样式值

Function:use $ define variables,store color、font style value and so on

$primary-color: #3498db;
.button { background: $primary-color; }

 2.嵌套(Nesting)

作用:嵌套选择器,反映 HTML 的层级关系。

Function: nest selector,reflect html's hierarchical relationship 

.nav {
  ul { margin: 0; }
  li { display: inline-block; }
  a {
    &:hover { color: red; } // 嵌套伪类
  }
}

3. 混入(Mixins) 

作用:通过 @include 复用样式块。

Function: reuse style pieces by '@include'

@mixin flex-center {
  display: flex;
  justify-content: center;
  align-items: center;
}
.box { @include flex-center; }

 4. 继承(Inheritance)

作用:通过 @extend 继承样式,减少重复代码。

Function: By @extend extend the style,reduce duplicate code.

.alert { padding: 15px; }
.error {
  @extend .alert;
  background: red;
}

5. 函数(Functions)

作用:内置函数(如 darken()lighten())或自定义函数处理样式值。

Function: Internal functions pr custom functions handle style values.

$base-color: #333;
.text { color: darken($base-color, 10%); }

 6. 条件语句(Control Directives)

作用:通过 @if@else if@else 实现条件逻辑。

Function: Conditional logic is implemented by @if, @else if, @else.

@mixin theme($color) {
  @if $color == light { background: white; }
  @else { background: dark; }
}

7. 循环(Loops)

作用:通过 @for@each@while 实现循环。

Function: implement loop by  @for@each@while

@each $animal in (cat, dog, bird) {
  .#{$animal}-icon { background: url(#{$animal}.png); }
}

 8. 模块化(Modules)

作用:通过 @use 和 @forward 管理样式依赖

Function: manage style dependencies through @use and  @forward

// utils/_variables.scss
$spacing: 10px;

// main.scss
@use 'utils/variables' as *;
.margin { margin: $spacing; }

 9. 占位符(Placeholders)

作用:定义 %placeholder 选择器,仅在通过 @extend 使用时生效。

Function: define  %placeholder selector,only effective when this is through useing @extend

%clearfix {
  &::after {
    content: '';
    display: table;
    clear: both;
  }
}
.container { @extend %clearfix; }

 10. 运算(Operations)

作用:直接在样式值中进行数学运算。

Function: do the math directly in the style values

.box { width: 100px + 20px; } // 输出 width: 120px;

 11. 插值(Interpolation)

作用:通过 #{} 将变量或表达式嵌入选择器和属性名。

Function:let  variable inlay selector and Attribute name through through #{}

相关文章:

  • LangChain开发(九)基于Rag实现文档问答
  • 啸叫抑制(AFS)从算法仿真到工程源码实现-第四节-数据仿真
  • Day15 -实例 端口扫描工具 WAF识别工具的使用
  • 【MyBatisPlus】MyBatisPlus介绍与使用
  • spring boot + thymeleaf整合完整例子
  • ES6-Symbol
  • CTF题目《高明的黑客》(强网杯 2019)Write up
  • 靶场(十八)---小白心得思路分享---shenzi
  • 数据库三级填空+应用(2)
  • 使用 gone.WrapFunctionProvider 快速接入第三方服务
  • vue数字公式篇 Tinymce结合使用(二)
  • Python图像处理——基于CSRNet的人群密度检测系统(Pytorch框架)
  • 【Spring AI】基于专属知识库的RAG智能问答小程序开发——功能优化:用户鉴权相关工具类代码
  • 基于深度学习的图像识别技术在智能安防中的应用
  • 设计模式代码
  • 【sylar-webserver】5 协程调度模块
  • Django之旅:第六节--mysql数据库操作增删改查(二)
  • 【程序人生】我的holland原书版职业测试分析
  • 鸿蒙Flutter实战:19-Flutter集成高德地图,跳转页面方式
  • LLM(大语言模型)的算子融合技术
  • 中国空间站首批在轨繁育果蝇即将返回地球,有望获得多项科学成果
  • 习近平对辽宁辽阳市白塔区一饭店火灾事故作出重要指示
  • 伊朗内政部长:港口爆炸由于“疏忽”和未遵守安全规定造成
  • 五一期间上海景观照明开启重大活动模式,外滩不展演光影秀
  • 解放日报头版头条:“五个中心”蹄疾步稳谱新篇
  • 全过程人民民主研究基地揭牌,为推动我国民主政治建设贡献上海智慧