css预处理器(less、sass)
发布日期:2021-05-14 23:07:52 浏览次数:16 分类:精选文章

本文共 1732 字,大约阅读时间需要 5 分钟。

LESS 和 Sass rhetorical installation Guide

1. LESS Installation

Node.js Requirements

  • First, ensure you have node.js installed. You can verify this by running node -v.
  • For global installation:
    • Use npm install -g less for global installation. Note:32-bit systems may need管理员权限。
    • To install with管理员权限: sudo npm install -g less.
  • For VS Code users, no installation is needed. Use the "Easy Less" plugin instead.
  • Sass indentation: Copy the following command and paste it into your终(ansiffer):
npm install -g less

VSCode Initialization

  • Open VS Code.
  • Go to Extensions.
  • Search for "Easy Less" and install it.
  • Create .css.less文件,使用 extensions 会自动处理文件。

Sass Installation

Node.js Requirements

  • Install node.js first.

Vogue Code installation

  • Install the "Live Sass Compiler" extension from Extensions.
  • Restart the editor, and you'll see a watcher in the bottom-right corner.

使用指南

  • Create .css.sass文件,引入文件到你的 HTML 中。
  • 例如,在你的 HTML head 中添加:

Sass Syntax Usage

Variables

$width: 200px;
$url: '../img/';
@mixin box1 {
width: $width;
background: url("#{$num}01.png");
}
  • Variables' scope: Only valid within the immediate block。
  • String interpolation: Use #{} in strings when using variables.

Mixins

.box2 {
@include box1;
height: 100px;
}
.box3() {
@include box1;
}

Control directives

่าส ///企业 循环
@for $num from 1 to 5 {
.item:nth-child(#{$num}) {
width: $num * 1px;
}
}

Compilation Styles

quality 可以是:Nested,Expanded,Compact,compressed

  • Nested: 缩进方式,后面的选择器对齐在最后一个大括号内。
  • Expanded: 无缩进。
  • Compact: Selection另一行整体紧凑。
  • compressed: 最终代码无空格,紧凑。

使用工具如 Koala 软件进行优化:

如果您需要更好的代码压缩,尝试Koala:

  • 将文件名确保没有中文字符。
  • 启动 Kola。
  • 选择 auto compile,或手动编译文件。
  • 总结

    安装和配置 LESS 和 Sass 不论是全局还是在 VS Code / WebStorm 中,主要操作方式都与 Node.js 一致。通过合理使用变量、混合、判断和控制指令,可以显著提升你的 CSS 设计效率。

    上一篇:css进阶篇(定位、浮动)
    下一篇:css动画相关(animation、transform、2d3d、transition)

    发表评论

    最新留言

    做的很好,不错不错
    [***.243.131.199]2025年04月23日 09时53分20秒

    关于作者

        喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
    -- 愿君每日到此一游!

    推荐文章