scss和sass区别_Sass和SCSS有什么区别?

scss和sass区别_Sass和SCSS有什么区别?scss 和 sass 区别 Thisistheupd 2014 这是最初于 2014 年 4 月 28 日发布的文章的更新版本 I vewrittenalo butsomecomme

scss和sass区别

Sass or SCSS

This is the updated version of an article originally published on April 28, 2014.

这是最初于2014年4月28日发布的文章的更新版本。

I’ve written a lot on Sass, but some comments I got made it clear that not everyone knows exactly what Sass refers to. Here’s a bit of clarity:

我已经在Sass上写了很多东西 ,但是我得到的一些评论清楚地表明,并不是每个人都确切知道Sass指的是什么。 这有点清楚:

When we talk about Sass, we usually refer to the preprocessor and the language as a whole. We’ll say, for example, “we are using Sass”, or “here is a Sass mixin”. Meanwhile, Sass (the preprocessor) allows two different syntaxes:

在谈论Sass时 ,我们通常指的是预处理器和整个语言。 例如,我们将说“我们正在使用Sass”或“这是Sass mixin”。 同时,Sass(预处理器)允许两种不同的语法:

  • Sass, also known as the indented syntax

    Sass ,也称为缩进语法

  • SCSS, a CSS-like syntax

    SCSS ,类似于CSS的语法

萨斯的历史 (History of Sass)

Initially, Sass was part of another preprocessor called Haml, designed and written by Ruby developers. Because of that, Sass stylesheets were using a Ruby-like syntax with no braces, no semi-colons and a strict indentation, like this:

最初,Sass是另一个名为Haml的预处理器的一部分,该预处理器由Ruby开发人员设计和编写。 因此,Sass样式表使用的是类似Ruby的语法,没有大括号,没有分号和严格的缩进,如下所示:

// Variable !primary-color= hotpink // Mixin =border-radius(!radius) -webkit-border-radius= !radius -moz-border-radius= !radius border-radius= !radius .my-element color= !primary-color width= 100% overflow= hidden .my-other-element +border-radius(5px)

As you can see, this is quite a change compared to regular CSS! Even if you’re a Sass (the preprocessor) user, you can see this is pretty different from what we are used to. The variable sign is ! and not $, the assignment sign is = and not :. Pretty weird.

如您所见,与常规CSS相比,这是一个很大的变化! 即使您是Sass(预处理器)用户,您也可以看到这与我们以前的习惯完全不同。 可变符号是! 不是$ ,分配符号是=而不是: 。 很奇怪

But that’s how Sass looked like until version 3.0 arrived in May 2010, introducing a whole new syntax called SCSS for Sassy CSS. This syntax aimed at closing the gap between Sass and CSS by bringing a CSS-friendly syntax.

但这就是Sass在3.0版于2010年5月问世之前的样子,它引入了一种全新的语法,称为SCSS for Sassy CSS 。 该语法旨在通过引入CSS友好语法来缩小Sass与CSS之间的差距。

// Variable $primary-color: hotpink; // Mixin @mixin border-radius($radius) { -webkit-border-radius: $radius; -moz-border-radius: $radius; border-radius: $radius; } .my-element { color: $primary-color; width: 100%; overflow: hidden; } .my-other-element { @include border-radius(5px); }

SCSS is definitely closer to CSS than Sass. That being said, Sass maintainers have also worked to make both syntaxes closer to each other by moving ! (variable sign) and = (assignment sign) from the indented syntax to $ and : from SCSS.

SCSS绝对比Sass更接近CSS。 话虽如此,Sass维护人员还通过移动!来使两种语法更加接近! 缩进语法中的(变量符号)和= (赋值符号)从SCSS转换为$:

Now, when starting a new project, you may wonder which syntax you should use. Let me enlighten the path and explain the pros and cons of each syntax.

现在,当开始一个新项目时,您可能想知道应该使用哪种语法。 让我启发一下道路,并解释每种语法的利弊。

Sass缩进语法的优点 (Pros for Sass Indented Syntax)

While this syntax might look weird, it has some interesting points. First of all, it is shorter and easier to type. No more braces and semi-colons, you don’t need all that stuff. Even better! No need for @mixin or @include, when a single character is enough: = and +.

尽管此语法看起来很怪异,但它有一些有趣的地方。 首先,它更短,更容易键入 。 不再需要花括号和分号,您不需要所有这些东西。 更好! 当一个字符就足够时,不需要@mixin@include=+

Also the Sass syntax enforces clean coding standards by relying on indentation. Because a wrong indent is likely to break the whole .sass stylesheet, it makes sure the code is clean and well formatted at all times. There is one way to write Sass code: the good way.

此外,Sass语法通过依赖缩进来强制执行干净的编码标准 。 由于错误的缩进可能会破坏整个.sass样式表,因此可以确保代码始终干净且格式正确。 编写Sass代码的方法有一种:好的方法。

But beware! Indenting means something in Sass. When indenting a selector, it means it is nested into the previous selector. For instance:

但是要当心! 缩进意味着 Sass中的东西 。 缩进选择器时,表示它嵌套在前一个选择器中。 例如:

.element-a color: hotpink .element-b float: left

… will output the following CSS:

…将输出以下CSS:

.element-a { color: hotpink; } .element-a .element-b { float: left; }

The simple fact of pushing .element-b one level to the right means it is a child of .element-a, changing the resulting CSS. Be very careful with your indentation!

向右推.element-b一个简单的事实意味着它是.element-a的子.element-a ,更改了结果CSS。 小心缩进!

As an aside, I feel like the indentation based syntax will probably suit a Ruby/Python team more than a PHP/Java team (although this is debatable, and I’d love to hear opinions to the contrary).

顺便说一句,我觉得基于缩进的语法可能更适合Ruby / Python团队而不是PHP / Java团队(尽管这值得商bat,我很想听听相反的意见)。

SCSS语法的优点 (Pros for SCSS Syntax)

For starter, it is fully CSS compliant. It means, you can rename a CSS file in .scss and it will just work. Making SCSS fully compatible with CSS has always been a priority for Sass maintainers since SCSS was released, and this is a big deal in my opinion. Moreover, they try to stick as close as possible to what could become a valid CSS syntax in the future (hence @directives).

首先,它完全符合CSS要求 。 这意味着,您可以在.scss重命名CSS文件,它将正常工作 。 自从SCSS发布以来,使SCSS与CSS完全兼容一直是Sass维护人员的优先考虑的事情,我认为这是很大的事情。 而且,他们尝试尽可能地贴近将来可能成为有效CSS语法的内容(因此@directives )。

Because SCSS is compatible with CSS, it means there is little to no learning curve. The syntax is already known: after all, it’s just CSS with a few extras. This is important when working with inexperienced developers: they will be able to quickly start coding without knowing the first thing about Sass.

由于SCSS与CSS兼容,这意味着几乎没有学习曲线 。 语法是已知的:毕竟,它只是CSS,还有一些其他功能。 与经验不足的开发人员一起工作时,这一点很重要:他们将能够快速开始编码,而无需了解Sass的第一手资料。

Moreover, it is easier to read because it actually makes sense. When you read @mixin, you know it is a mixin declaration; when you see @include, you are calling a mixin. It doesn’t make any shortcuts, and everything makes sense when read out loud.

此外,它更容易阅读,因为它确实有意义。 当您阅读@mixin ,您知道它是一个mixin声明; 当您看到@include ,您正在调用mixin。 它没有任何捷径,大声读出时一切都有意义。

Also, most existing tools, plugins and demos for Sass are developed using the SCSS syntax. As time goes, this syntax is becoming pre-eminent and the default choice, mostly for the above reasons.

而且,大多数现有的Sass工具,插件和演示都是使用SCSS语法开发的。 随着时间的流逝,主要由于上述原因,该语法正变得越来越突出,并且成为默认选择。

最后的想法 (Final Thoughts)

The choice is up to you, but unless you have really good reasons to code using the indented syntax, I would strongly suggest using SCSS over Sass. Not only is it simpler, but it is also more convenient.

选择取决于您,但是除非您有充分的理由使用缩进语法进行编码,否则我强烈建议您在Sass上使用SCSS。 它不仅更简单,而且也更加方便。

I once tried the indented syntax myself and liked it. I liked how short and easy it was. I was actually about to move an entire code base to Sass at work before changing my mind at the last minute. I thank my past-self for halting that move, because it would have been very difficult to work with several of our tools had we used the indented syntax.

我曾经亲自尝试过缩进语法并喜欢它。 我喜欢那又短又容易。 实际上,在最后一刻改变主意之前,我实际上打算将整个代码库移交给Sass。 我感谢我过去的努力停止了这一步,因为如果使用缩进语法,使用我们的一些工具将非常困难。

Also, please note Sass is never in uppercase, no matter whether you’re talking about the language or the syntax. Meanwhile, SCSS is always in uppercase. Need a reminder? SassnotSASS.com to the rescue!

另外,请注意,无论您是在谈论语言还是语法, Sass都不会大写。 同时, SCSS始终为大写。 需要提醒吗? SassnotSASS.com进行救援!

翻译自: https://www.sitepoint.com/whats-difference-sass-scss/

scss和sass区别

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/233559.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Android 文件夹_安卓文档在哪个文件夹

    Android 文件夹_安卓文档在哪个文件夹【文件夹功能简介】/system/app这个里面主要存放的是常规下载的应用程序,可以看到都是以APK格式结尾的文件。在这个文件夹下的程序为系统默认的组件,自己安装的软件将不会出现在这里,而是/data/文件夹中。/system/bin这个目录下的文件都是系统的本地程序,从bin文件夹名称可以看出是binary二进制的程序,里面主要是Linux系统自带的组件(命令)/system/etc从文件夹名称来看保存的都是系统的配置文件,比如APN接入点设置等核心配置。/system/fonts字体文件夹,除了标准字体

    2022年10月16日
    0
  • VS2005卸载问题「建议收藏」

    VS2005卸载问题「建议收藏」由于本人的VS2005是中英文结合的(先安装了中文版的,卸载不彻底后,又安装了英文版,造成了中英文结合的),所以在开发的时候,在遇到一些细节的时候,总是会存在编译错误,就是由于这种结合体造成的,为了净化自己的开发环境,今天决定彻底的删除这个结合体,该为英文版。重装了好几次终于成功。以下为成功步骤:先在“控制面板”的“添加删除程序中”删除所有相关…

    2022年9月24日
    0
  • 基于协同过滤的电影推荐系统的设计与实现(协同过滤推荐算法伪代码)

    1Mahout介绍ApacheMahout是ApacheSoftwareFoundation(ASF)旗下的一个开源项目,提供一些可扩展的机器学习领域经典算法的实现,旨在帮助开发人员更加方便快捷地创建智能应用程序。经典算法包括聚类、分类、协同过滤、进化编程等等,并且,在Mahout中还加入了对ApacheHadoop的支持,使这些算法可以更高效的运行在云计算环境中。…

    2022年4月11日
    319
  • MiniPCIE打板需要注意的细节[通俗易懂]

    MiniPCIE打板需要注意的细节[通俗易懂]Minipcie可以不用做斜边,重要的是板厚1.0

    2022年9月8日
    0
  • matlab 柱状图不同颜色(取巧哈)[通俗易懂]

    matlab 柱状图不同颜色(取巧哈)[通俗易懂]以前写过一个颜色索引的柱状图,但是年代久远想不起来了。今天需要出一个不同颜色的柱状图,看了一下博客,首先使用了matlab中的children,但是发现颜色没有变化。后来从另外的博客中发现,matalb2014以后的版本这个功能不能用了,what?只能用bar。好吧,用bar一遍一遍写,这里做个取巧的方式哈。mydata=[0.5,1.5,2.5,3.5,4.5];figure(1)holdonfori=1:length(mydata)h=bar(i,mydata.

    2022年10月10日
    0
  • linux软件_LINUX教程

    linux软件_LINUX教程常用指令ls      显示文件或目录   -l     列出文件详细信息l(list)   -a     列出当前目录下所有文件及目录,包括隐藏的a(all)mkdir    创建目录   -p     创建目录,若无父目录,则创建p(parent)cd       切

    2022年9月1日
    0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号