Thumbnail
Category: Lập trình

Kinh nghiệm SASS - SCSS

Date: January 5, 2021
10 views

1. Xếp chồng


ul {
  list-style-type: none;
  
  li {
    padding: 12px;
    border-radius: 5px;
    
    a {
      text-decoration: none;
    }
  }
}

2. Biến


$tenBien: giaTri;
//vd:
$color: blue;

3. Mixin

Giống hàm, có thể xài lại

3.1 Không có tham số


@mixin tenMixin() {
    //code css 
}
.button_1 {
    @include tenMixin; 
}

3.2 Có tham số


@mixin tenMixin($tenBien) {
    //code css 
}
.button_1 {
    @include tenMixin(giaTri); 
}
//ví dụ
@mixin tenMixin($color) {
    //code css 
}
.button_1 {
    @include tenMixin(red); 
}

4. Kế thừa


%tenMuonDat {
    //code css 
}
.button_1 {
    @extend %tenMuonDat; 
}

5. Câu điều kiện


@if $tenBien == giaTri {
    //code css
}

6. Thêm file scss

Lưu ý: tên file cần import nên đặt tên _tenFile.scss để không biên dịch ra nhiều file.


@import "tenFile"; // không cần .scss
//ví dụ:
@import "_header";

7. Khóa học ngắn về scss của Thạch Phạm

8. Phần mềm Koala để biên dịch file scss => css

8.1 Koala

http://koala-app.com/

 

8.2 Node js


npm install -g sass
  
sass --watch file.SCSS file.css 

Copyright © 2025 All Right Reserved