Simple application of SASS

Source: Internet
Author: User
Tags css preprocessor

Sass is a CSS preprocessor with powerful syntax and functions, and the more friendly variables are named for less than less, gaining a lot of programmer's favorite. and Sass now supports the full CSS3, which is why programmers love sass.

Installation of SASS

Sass is installed in three ways, command line tools, standalone ruby modules and as a framework plugin

The first kind of installation and use is like this:

Gem Install Sass

If you are using a Windows operating system, you must also first install Ruby

In order to run sass, you can do this

Sass Input.scss Output.css

And you can also listen to the disk

Sass--watch Input.scss:output.css

Very convenient.

Installation and use do not repeat too much, below to see a small example with sass

#main p {  color: #00ff00;  width:97%; }  #main p. redbox {    background-color: #ff0000;    Color: #000000; }

The top is sass, and see how it compiles.

#main p {  color: #00ff00;  width:97%;  . Redbox {    background-color: #ff0000;    Color: #000000;  }}

Is it feeling very convenient, soon Czech? Instead of using CSS as before, Sass has a hierarchical relationship that makes it easier for programmers to think about how to write structures.

#main {  width:97%;  P, div {    font-size:2em;    a {font-weight:bold;}  }  Pre {font-size:3em;}}

For a better example, we look at this sass structure and know that P tags and div notes are descendants of the ID as the main element, and they are at the same level, at a glance, very handy

Post-compilation results:

#main {  width:97%;}  #main p, #main div {    font-size:2em;}    #main p A, #main div a {      font-weight:bold;}  #main Pre {    font-size:3em;}

  

More examples

Variable declaration

$width: 5em;

  

#main {  width: $width;}

  

#main {  $width: 5em!global;  Width: $width;} #sidebar {  width: $width;}

Post-compilation results:

#main {  width:5em;} #sidebar {  width:5em;}

It's so cool, there's wood.

Sass Grammar and form and less, if mastered less, I believe sass will soon grasp

Simple application of SASS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.