First time using Sass
Look at the sass tutorial of senior materliu on MOOC.com, http://www.imooc.com/learn/364. By the way, I will restructure the project I just finished and write down some notes and experiences here~
First install sass, here you can directly refer to Senior Desert’s installation tutorial http://www.w3cplus.com/sassguide/install.html.
Then install compass, type the command in ruby command, gem install compass. At this stage, I don’t understand much about compass. After watching the sass video, I feel that it is only used to compile scss files and compress css for the time being. (fog).
Compass command:
compass create compass;
Compass watch;
Sass syntax:
When the file does not need to be compiled, it can be marked with _ prefix and underscore and then named. Usually functions or variables are placed in a folder.
You can use import to import files, and the file name suffix does not need to be written. However, this is not a native CSS import.
Two major disadvantages of native CSS import: 1. It must be placed at the front of the code. 2. It is detrimental to performance. If you really want to use native import, then: 1. When it ends with css. 2. Start with http://. 3. URL() function. 4. With media queries.
Sass variables: Good thing. For example, every time you look for a color, you can’t remember the color code. If you use variables, you don’t have to look for the color code so slowly. You can just look at the variable file and it will be clear at a glance.
Special variables, variables used in specific situations;
eg:
<span style="color: #800000;">//普通变量及其使用 $common-ff :"微软雅黑"; //字体设置 body</span>{<span style="color: #ff0000;"> font-family</span>:<span style="color: #0000ff;"> $common-ff</span>; }<span style="color: #800000;"> //css输出---- body</span>{<span style="color: #ff0000;"> font-family</span>:<span style="color: #0000ff;"> "微软雅黑"</span>; }<span style="color: #800000;"> //特殊变量 $direction: top; //应用于class和属性 .border-#</span>{<span style="color: #ff0000;">$direction</span>}{<span style="color: #ff0000;"> border-#{$direction</span>}<span style="color: #800000;">:1px solid #ccc; } //应用于特殊属性同理</span>
Multi-valued variable: As the name suggests, it means multiple values. For example, 0 1px 2px 3px and so on. There are many functions in it, and I have only used append($list,$value,[$separator]) for the time being.
Mixin: declared through @mixin, called by @include;
When I was working on a project, I used Flexible to write a lot of styles like this
<span style="color: #800000;">button,input,textarea</span>{<span style="color: #ff0000;"> font-size</span>:<span style="color: #0000ff;"> 12px</span>; }<span style="color: #800000;"> [data-dpr="2"] button, [data-dpr="2"] input, [data-dpr="2"] textarea</span>{<span style="color: #ff0000;"> font-size</span>:<span style="color: #0000ff;"> 24px</span>; }<span style="color: #800000;"> [data-dpr="3"] button, [data-dpr="3"] input, [data-dpr="3"] textarea</span>{<span style="color: #ff0000;"> font-size</span>:<span style="color: #0000ff;"> 36px</span>; }
It’s too troublesome to write like this, so after learning sass, I wrote one myself by referring to the hybrid macros they wrote on Taobao.com
<span style="color: #800000;">@mixin property-dpr($property,$px-values)</span>{<span style="color: #ff0000;"> //判断参数是不是单个数字,若是 @if type-of($px-values) == "number"{ #{$property</span>}<span style="color: #800000;">: $px-values; [data-dpr="2"] & </span>{<span style="color: #ff0000;"> #{$property</span>}<span style="color: #800000;">: $px-values * 2; } [data-dpr="3"] & </span>{<span style="color: #ff0000;"> #{$property</span>}<span style="color: #800000;">: $px-values * 3; } } //若为数组则 @else </span>{<span style="color: #ff0000;"> //新建两个空数组 $twodpr-values</span>:<span style="color: #0000ff;">()</span>;<span style="color: #ff0000;"> $threedpr-values</span>:<span style="color: #0000ff;">()</span>;<span style="color: #ff0000;"> //遍历多值变量 @each $value in $px-values{ $twodpr-values</span>:<span style="color: #0000ff;">append($twodpr-values,$value*2)</span>;<span style="color: #ff0000;"> $threedpr-values</span>:<span style="color: #0000ff;">append($threedpr-values,$value*3) </span>}<span style="color: #800000;"> // 返回处理后的多值变量 #</span>{<span style="color: #ff0000;">$property</span>}<span style="color: #800000;">: $px-values; [data-dpr="2"] & </span>{<span style="color: #ff0000;"> #{$property</span>}<span style="color: #800000;">: $twodpr-values; } [data-dpr="3"] & </span>{<span style="color: #ff0000;"> #{$property</span>}<span style="color: #800000;">: $threedpr-values; } } }</span>
css, sass generated code:
<span style="color: #800000;">//调用mixin div</span>{<span style="color: #ff0000;"> @include property-dpr(font-size,12px); </span>}<span style="color: #800000;"> //css style div </span>{<span style="color: #ff0000;"> font-size</span>:<span style="color: #0000ff;"> 12px</span>; } <span style="color: #008000;">/*</span><span style="color: #008000;"> line 7, ../../sass/common/_mixin.scss </span><span style="color: #008000;">*/</span><span style="color: #800000;"> [data-dpr="2"] div </span>{<span style="color: #ff0000;"> font-size</span>:<span style="color: #0000ff;"> 24px</span>; } <span style="color: #008000;">/*</span><span style="color: #008000;"> line 10, ../../sass/common/_mixin.scss </span><span style="color: #008000;">*/</span><span style="color: #800000;"> [data-dpr="3"] div </span>{<span style="color: #ff0000;"> font-size</span>:<span style="color: #0000ff;"> 36px</span>; }
That’s it for today.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...
