我的网站开发技术经验总结 我的网站开发技术经验总结
首页

fangdown

我的网站开发技术经验总结
首页
  • 大前端

  • 基础

    • js

    • css

      • 如何让chrome实现小于12px的字体大小
      • 如何使用css画出三角形,正方形
      • 如何使用CSS完成视差滚动效果
      • 说说单行和多行文本溢出的实现方式
      • 说说对Css预编语言的理解
        • 是什么
        • 常用
        • 区别
          • 变量
          • 作用域
          • 代码混合
          • 嵌套
          • 代码模块化
      • 说说你对CSS盒子模型的理解
      • 说说设备像素、css像素、设备独立像素、dpr、ppi 之间的区别
      • 说说什么是响应式设计及实现方式
      • 说说什么是重绘和回流,如何优化
      • 说说元素水平垂直居中的方法有哪些
      • 说说CSS3新增了哪些新特性
      • 说说css性能优化有哪些方式
      • 说说css中层叠上下文z-index的理解
      • 说说css中的选择器是优先级
      • 说说css中两栏布局和三栏布局有哪些
      • 说说css中哪些属性是继承和不继承的
      • 说说css中实现动画有哪些
      • 说说CSS中有哪些方式可以隐藏页面元素
      • 说说em-px-rem-vh-vw的区别
      • 说说flex盒子的理解及应用
      • 说说property和prototype的区别
      • 谈谈你对BFC的理解
    • ES6

  • 框架

  • 情商

  • 算法

  • 网络

  • 千锤百炼
  • 基础
  • css
fangdown
2021-08-25
目录

说说对Css预编语言的理解

# 是什么

css预编语言:是css的超集, 增加了变量、混合、函数等功能,让css维护更方便

# 常用

  • sass
  • less
  • stylus
/* less scss */
.box {
  display: block;
}
/* sass */
.box
  display: block
/* stylus */
.box
  display: block

# 区别

  • 变量
  • 作用域
  • 代码混合
  • 嵌套
  • 代码模块化

# 变量

  • less @开头
  • sass $开头
/* less */
@red: #c00;

strong {
  color: @red;
}
/* sass */
$red: #c00;

strong {
  color: $red;
}
/* stylus */
red = #c00

strong
  color: red

# 作用域

  • sass 不存在作用域
  • less/stylue 会一级一级往上查找
$color: black;
.scoped {
  $bg: blue;
  $color: white;
  color: $color;
  background-color:$bg;
}
.unscoped {
  color:$color;
} 
/* 编译后 */
.scoped {
  color:white;/*是白色*/
  background-color:blue;
}
.unscoped {
  color:white;/*白色(无全局变量概念)*/
} 
@color: black;
.scoped {
  @bg: blue;
  @color: white;
  color: @color;
  background-color:@bg;
}
.unscoped {
  color:@color;
} 
/* 编译后 */
.scoped {
  color:white;/*白色(调用了局部变量)*/
  background-color:blue;
}
.unscoped {
  color:black;/*黑色(调用了全局变量)*/
} 

# 代码混合

  • less
.alert {
  font-weight: 700;
}

.highlight(@color: red) {
  font-size: 1.2em;
  color: @color;
}

.heads-up {
  .alert;
  .highlight(red);
}
  • sass
/* sass */
@mixin large-text {
  font: {
    family: Arial;
    size: 20px;
    weight: bold;
  }
  color: #ff0000;
}

.page-title {
  @include large-text;
  padding: 4px;
  margin-top: 10px;
}
  • stylue
error(borderWidth= 2px) {
  border: borderWidth solid #F00;
  color: #F00;
}
.generic-error {
  padding: 20px;
  margin: 4px;
  error(); /* 调用error mixins */
}
.login-error {
  left: 12px;
  position: absolute;
  top: 20px;
  error(5px); /* 调用error mixins,并将参数$borderWidth的值指定为5px */
} 

# 嵌套

通用

.a {
  &.b {
    color: red;
  }
}

# 代码模块化


@import './common';
@import './github-markdown';
@import './mixin';
@import './variables';
上次更新: 2021/12/19, 18:05:42
说说单行和多行文本溢出的实现方式
说说你对CSS盒子模型的理解

← 说说单行和多行文本溢出的实现方式 说说你对CSS盒子模型的理解→

最近更新
01
多分支修复撞车的问题
05-01
02
如何成为架构师
01-23
03
服务器部署全过程
11-23
更多文章>
Theme by Vdoing | Copyright © 2019-2026 fangdown | 粤ICP备19079809号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式