简体   繁体   English

与CSS相比如何使用Sass(SCSS)

[英]How to use sass (scss) compared to css

So to start off, let me introduce myself as a complete beginner. 因此,首先让我介绍一下自己作为一个完整的初学者。 I want to get startet with scss, but I'm confused about how it works in regards to my css file. 我想对scss有所了解,但是我对它在CSS文件方面的工作方式感到困惑。 After having set of sass, and compiled my css to sass, should I then link my html to the sass file instead of to the css? 在设置了sass之后,将我的css编译为sass,然后我应该将html链接到sass文件而不是css吗? And would I then delete my css file from the FTP and instead upload the sass file? 然后我要从FTP删除css文件,然后上传sass文件吗?

Thanks, Jonas the newbie. 谢谢,新手乔纳斯。

scss or sass files are an improved syntax to write CSS, but remember that browsers can only understand CSS files. scss或sass文件是编写CSS的改进语法,但是请记住,浏览器只能理解CSS文件。 You can write a file with the sass or scss syntax, then compile it to a css file, and link this css file in your html file. 您可以使用sass或scss语法编写文件,然后将其编译为css文件,并将此css文件链接到html文件中。 So no, you will never upload anything else than the css file to your FTP. 所以不,除了css文件外,您永远不会将其他任何文件上传到您的FTP。

Nope. 不。 Scss file is just for you to write code in more convenient style. Scss文件只为您以更方便的样式编写代码。 You should link html to main css file. 您应该将html链接到主CSS文件。 And put on server only css file. 并放在服务器上仅css文件。

Good practice is break scss in small pieces and import to one scss file, which is transpiled to css. 好的做法是将scss分成小块,然后导入到一个scss文件中,然后将其转换为css。

F. ex. F.前 my main.scss file (transpiling to main.css linked to html site) looks like this: 我的main.scss文件(转换为链接到html站点的main.css)看起来像这样:

// Layout
@import '_layout/_navbar';
@import '_layout/_main';
@import '_layout/_footer';
@import '_layout/_header';
@import '_layout/_blog';
@import '_layout/_aside';

// Components (you can replace the below ones to bootstrap or other framework's files just with components)
@import '_components/_blockquote';
....

This is the biggest asset of scss. 这是scss的最大资产。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM