[Ruby on Rails series] 5. Topics: Talk about sass

Source: Internet
Author: User
Tags ruby on rails

This is my presentation in the rails lecture of hosei University.

I will introduce Sass by 5 examples.

 

1, what is sass?

We can get into the official site of sass.

The official site give the definition of sass.

Sass is the most mature, stable, and powerful professional grade CSS extension language in the world.

 

[Here are someCharactersOf sass]

• Sass (syntactically awesome stylesheets) is a Stylesheet Language

• Sass is a scripting language that is interpreted into Cascading Style Sheets (CSS ).

• Sass (in the larger context of both syntaxes) extends CSS by providing several mechanisms available in more traditional programming languages, special object-oriented languages, but that are not available to css3 itself.

• Sass is simply syntactic sugar for CSS

 

2, How to Write sass

How to Write sass? If I just want to try, do I need setup environment?

 

It is very easy to write sass code. If you just want to try, you do not need config your environment. What you should do is using this website: http://sassmeister.com/

You can test your code here. it is a cool web environment to write sass code. you write sass code, then the environment will transfer it to CSS code. it is so cool to use it.

 

3, some examples

Now I get some examples to write sass.

[Example 1] Variables

Sass allow us to define variables.

Sass code is here:

$blue : #1875e7;div {color : $blue;}

It will be transfer to CSS code.

Now I write HTML code to test it.

The result:

 

[Example 2] computing

 

Sass allow us to write some expression. Then it will computing the expression.

Sass code is here:

 

[Example 3] nesting

 

CSS does support logical nesting, but the code blocks themselves are not nested. Sass allows the nested code to be inserted within each other.

 

Sass code:

nav {  ul {     margin: 0;     padding: 0;     list-style: none;  }   li {     display: inline-block;   }   a {     display: block;     padding: 6px 12px;     text-decoration: none;   } }

CSS code will be automatic generated:

HTML code and test:

 

[Example 4] mixins

 

Mixins is just like the macro in C program language.

Sass code:

@mixin left ($value: 10px) {float: left;margin-left: $value;}div  {  @include left (30px)}

 

[Example 5] selector inheritance

 

Sass code:

.message {  border: 1px solid #ccc;  padding: 10px;  color: #333;}.success {  @extend .message;  border-color: green;}.error {  @extend .message;  border-color: red;}.warning {  @extend .message;  border-color: yellow;}

 

[Example 6] Function

 

Sass code:

@function changecolor ($color) {@return $color;}#sidebar {color: changecolor(red);}

 

 

It is very interesting! Just enjoy it!

[Ruby on Rails series] 5. Topics: Talk about sass

Related Article

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.