sass导入sass

The greatest challenge for most developers to learning Sass isn’t the concept of preprocessors, or the language itself, but the hoops that must be jumped through to get it up and running. Those comfortable with the command line can get things going fairly easily, and tools like CodeKit help immensely, but that still leaves many designer-developers who might otherwise become Sass aficionados intimidated by change, wary of paying for a new tool, or simply overwhelmed at the prospect of changing their entire workflow.

对于大多数开发人员而言,学习Sass的最大挑战不是预处理器的概念或语言本身,而是必须跳过去才能使Sass投入运行的障碍。 那些熟悉命令行的人可以很轻松地进行操作,而CodeKit之类的工具可以提供极大的帮助,但这仍然使许多设计人员-开发人员可能因更改而被Sass迷住,对购买新工具不屑一顾 ,或者只是不知所措改变他们整个工作流程的前景。

For those interested in learning Sass, I’d suggest taking a route that entirely avoids any up-front investment, has no long-term commitment, and demands very little time: CodePen. That way, you can start coding Sass in just three simple steps:

对于那些对学习Sass感兴趣的人,我建议您采取一条完全避免任何前期投资,没有长期承诺并且需要很少时间的方法: CodePen 。 这样,您只需三个简单的步骤即可开始对Sass进行编码:

  1. Go to CodePen.io

    转到CodePen.io

  2. Click on New Pen in the top left

    点击左上角的新笔

  3. On the screen that appears, click on the gear icon next to CSS and choose Sass (.scss) in the new window. Click again on the same icon (or anywhere else on the screen) to close the window.

    在出现的屏幕上,单击CSS旁边的齿轮图标,然后在新窗口中选择Sass(.scss) 。 再次单击相同的图标(或屏幕上的其他任何位置)以关闭窗口。

That’s it: you’re now ready to start coding with Sass.

就是这样:您现在准备开始使用Sass进行编码。

为什么Sass语法有两种选择? (Why Two Choices of Sass Syntax?)

With version 3, Sass syntax took two possible paths: the original Sass syntax, and the new .scss format. True to its name, .scss syntax is very similar to CSS: it uses curly braces and semicolons for declarations, whereas the original .sass syntax relies on indentation and line returns. Both methods continue to be supported, but for the sake of clarity (and to ease the transition from CSS into Sass) I’ll use the .scss syntax here.

在版本3中,Sass语法采用了两种可能的路径:原始Sass语法和新的.scss格式。 .scss其名称一样, .scss语法与CSS非常相似:它使用花括号和分号进行声明,而原始的.sass语法依赖于缩进和行返回。 继续支持这两种方法,但是为了清楚起见(并简化从CSS到Sass的过渡),我将在此使用.scss语法。

轻而易举 (Easy Does It)

The first thing to realize is that, as a preprocessor, Sass supports everything that’s possible in CSS. In fact, you could write only vanilla CSS in a Sass file and everything would come out perfectly okay. Let’s prove that: type the following into the CodePen CSS panel:

首先要意识到的是,作为预处理器, Sass支持CSS中可能的一切 。 实际上,您只能在Sass文件中编写原始CSS,然后一切都会好起来的。 让我们证明一下:在CodePen CSS面板中键入以下内容:

body { background: goldenrod; }

You should see the preview pane light up with a new background: no new syntax required. Bottom line: you only need ever take on the Sass that you’re willing to use. Don’t know how to accomplish something in Sass? That’s fine: do it in CSS, right in the same stylesheet. You don’t need to learn an entire syntax all at once.

您应该看到预览窗格以新的背景亮起:不需要新的语法。 底线: 您只需要使用您愿意使用的Sass。 不知道如何在Sass中完成某事? 很好:在CSS中,在同一样式表中进行操作。 您无需一次学习全部语法。

In this article, we’ll start by using just one standout Sass feature.

在本文中,我们将仅使用一个出色的Sass功能。

亮线:颜色和变量 (Bright Lines: Colors & Variables)

As a web development project grows, things get forgotten. Sometimes you can avoid having to dredge up the past by using CSS inheritance; having a strong, authoritative site style guide also helps. But sometimes there’s no way to avoid the question of “what was that color again?” And we all know the results: redundant declarations scattered throughout the stylesheet, or, even worse, best guesses at the color.

随着Web开发项目的发展,事情被遗忘了。 有时您可以避免通过使用CSS继承来疏通过去; 拥有强大而权威的网站样式指南也有帮助。 但是有时没有办法避免出现“这种颜色又是什么?”的问题。 我们都知道结果:多余的声明散布在样式表中,或者甚至更糟的是猜测颜色。

If preprocessors had to justify their existence on one sole feature, it would be variables. CSS variables are coming to the standard W3C specification, but it will be years before they can be used in production. With a CSS preprocessor, you can use variables now, the Sass way.

如果预处理器必须在一个唯一的特征上证明它们的存在,那将是变量。 CSS变量已成为标准的W3C规范 ,但要在生产中使用还需要很多年。 使用CSS预处理器,您现在可以以Sass方式使用变量。

We’ll need some content on the page to see this effect. Click in the HTML tab and type the following:

我们需要页面上的一些内容才能看到此效果。 单击HTML选项卡,然后键入以下内容:

<h1>Burdensome Burliness</h1>

小费 (Tip)

Since CodePen also supports Emmet shortcuts, you could have typed h1, hit TAB on your keyboard, then entered the text content.

由于CodePen还支持Emmet快捷方式,因此您可以键入h1 ,在键盘上按TAB键,然后输入文本内容。

Then at the top of the CodePen CSS window, type the following:

然后在CodePen CSS窗口的顶部,键入以下内容:

$primtext: #333;

And adjust the CSS immediately below it to:

并将其下方CSS调整为:

body { background: goldenrod; color: $primtext; }

You’ll see that the text is dark grey. Adjust the value of the variable, and the color of the text will change accordingly. This will remain true no matter how often you reference the $primtext variable throughout your code. Centralizing colors – or any other value – into Sass variables makes on-the-fly design changes very easy.

您会看到文本为深灰色。 调整变量的值,文本的颜色将相应改变。 无论您在代码中$primtext引用一次$primtext变量,这都是正确的。 将颜色(或任何其他值)集中到Sass变量中,可以使动态设计更改变得非常容易。

注意 (Note)

It’s important to understand that the browser really only understands four basic front-end technologies: HTML, CSS,  JavaScript and media formats. That means that Sass must be translated into CSS before it can be sent to and rendered in the browser. You can see this for yourself: try right-clicking on the text in the preview window on CodePen and choosing Inspect Element. In the Styles window that appears, you’ll see the color of the <h1> element as #333, with no mention of any variable.

重要的是要了解浏览器实际上只了解四种基本的前端技术:HTML,CSS,JavaScript和媒体格式。 这意味着必须先将Sass转换为CSS,然后才能将其发送到浏览器并在浏览器中呈现 。 您可以自己查看:尝试在CodePen的预览窗口中右键单击文本,然后选择检查元素 。 在出现的“样式”窗口中,您将看到<h1>元素的颜色为#333 ,没有提及任何变量。

使用您所拥有的 (Using What You’ve Got)

That’s great in theory, but can we actually use what we’ve made? The answer is yes: CodePen is great for prototyping, and exporting our work will allow us to see the typical structure of a Sass project. To do so, click on the Save button, then Share. In the window that appears, choose Export .zip. Download and uncompress the .zip file; the result will look something like the screenshot below:

从理论上讲这很棒,但是我们可以实际使用我们所做的吗? 答案是肯定的:CodePen非常适合制作原型,导出我们的工作将使我们能够看到Sass项目的典型结构。 为此,请点击保存按钮,然后点击共享 。 在出现的窗口中,选择Export .zip 。 下载并解压缩.zip文件; 结果将类似于以下屏幕截图:

Typical small Sass site setup (the README file has been added by CodePen)
典型的小Sass站点设置(README文件已由CodePen添加)

You can see that the .scss file is in a folder; it may even be associated with an editor you already own. The final CSS stylesheet is also in a folder, which may be new to you: because the CSS is generated from any changes to the Sass file, a folder structure usually works best to contain it. The index page is linked to this CSS file, just like normal.

您会看到.scss文件在文件夹中; 它甚至可能与您已经拥有的编辑器相关联。 最终CSS样式表位于一个文件夹中,这可能是您不熟悉的:因为CSS是通过对Sass文件的任何更改生成的,所以通常最好使用文件夹结构来包含它。 索引页面链接到此CSS文件,就像正常情况一样。

The result is the typical structure of a simple Sass-driven project, with the final “build” of the site stylesheet contained in a single folder.

结果就是一个简单的由Sass驱动的项目的典型结构,最终,网站样式表的“构建”包含在一个文件夹中。

That’s the very basics of using Sass. While I’ll have a lot more to say about colors and variables, we’ll turn to looking at another killer Sass feature in the next article.

这是使用Sass的基本知识。 虽然我将对颜色和变量有更多的话要说,但我们将在下一篇文章中介绍另一个杀手S的Sass功能。

翻译自: https://thenewcode.com/978/Learning-Sass-with-CodePen-Part-One

sass导入sass

sass导入sass_使用CodePen学习Sass,第一部分相关推荐

  1. sass导入sass_如何使用Sass Mixins和Loops

    sass导入sass by Jason Arnold 杰森·阿诺德(Jason Arnold) 如何使用Sass Mixins和Loops (How to use Sass Mixins and Lo ...

  2. sass导入sass_SASS的力量

    sass导入sass 一点历史 (A bit of history) SASS appeared in 2006 and stands for Syntactically Awesome Styles ...

  3. 【Sass】+【Compass】学习笔记

    这两天一直在学习sass和compass,看完了一些教程后决定做一些实践操作,权当笔记记录一下. COMPASS:compass-style.org 安装compass:gem install com ...

  4. scss怎么引入到html,Sass 导入指令

    描述 导入指令,导入SASS或SCSS文件. 它直接需要导入文件名. 在SASS中导入的所有文件将在单个CSS文件中组合.当我们使用@import规则时,很少有事情编译到CSS:文件扩展名<.c ...

  5. [Sass常见用法] Css代码的Sass打开方式

    文章目录 Sass Sass是什么(英文全称:Syntactically Awesome Stylesheets) 为什么使用 Sass 数组 混合器 sass安装及用法实例 sass的安装 在开发软 ...

  6. 【Sass】437- 一文详解Sass新特性 - 模块

    本文来自[前端早读课],内容不错,推荐给大家. 前言 原来是今年才推出的.今日早读文章由@十方魔投稿分享. 正文从这开始-- 简介 2019年十月一号,sass团队推出了sass的模块化机制,通过新关 ...

  7. 学习java第一步_Spring Boot 学习第一步(搭建初步环境)

    学习一个东西的第一步是要学会如何迅速搭建起来一个可用的环境,也就是demo.这里我选择的开发环境是Eclipse, Maven + Spring Web 项目结构在Eclipse下面的实现 我们在这里 ...

  8. 《Go语言圣经》学习笔记 第一章 Go语言入门

    Go语言圣经学习笔记 第一章 Go语言入门 目录 Hello, World 命令行参数 查找重复的行 GIF动画 获取URL 并发获取多个URL Web服务 本章要点 注:学习<Go语言圣经&g ...

  9. Java学习总结第一阶段

    day1(甘特图)预科阶段 甘特图:让工程项目变成可视化图表,也叫项目进度规划表. 一般由:任务名称.工期.开始时间.完成时间.前置任务.资源名称.日期组成 如下所示,资源名称那就是人的名字,前置任务 ...

最新文章

  1. jQuery插件之ajaxFileUpload
  2. 如果ASM磁盘组由哪些物理磁盘组成?
  3. mysql 开发权限_mysql权限管理
  4. php写带分页的留言板,php中分页程序之基于留言板详解_PHP教程
  5. 看病(信息学奥赛一本通-T1371)
  6. 使用Microsoft数据迁移助手在Oracle数据库和SQL Server之间迁移的具体示例
  7. Playing Atari with Deep Reinforcement Learning 中文 讲解3
  8. 戴尔G7 7588 Windows 10 未安装任何音频输出设备
  9. Unity开发常用工具
  10. HTC M8t unlock Bootloader/Root/S-OFF/解网络锁笔记
  11. 飞腾服务器代理上网设置
  12. 画图取色小工具markman
  13. [LCT刷题][连通性维护] P3950 部落冲突
  14. 自用win软件小合集
  15. wagon-maven-plugin插件实现自动化构建部署到服务器
  16. 解决vue项目在ie浏览器中无法显示的问题,兼容低版本浏览器问题
  17. python机器人编程——四轴UARM机械臂的运动控制(逆解)原理及python实现(下)
  18. java socket / IM / Message / chat / liaotian / xmpp
  19. Qt官方示例-正则测试工具
  20. 计算机的风扇参数,电脑静音高效有诀窍 选购对风扇不可少

热门文章

  1. CarCol 老照片上色
  2. 我是你流浪过的一个地方——王海桑
  3. 局域网网中的病毒传播
  4. mui app自定义图标
  5. IOT数字世界和元宇宙
  6. C# Grasshopper自定义电池图标
  7. 关于属性和字段的初步了解
  8. vue3 组合式API使用第1篇-保证学得会
  9. macmini忘记密码怎么办
  10. c++ 11标准模板(STL) std::vector (八)