freecodecamp: Sass "Syntactically Awesome StyleSheets"
from back-end to front-end
Store Data with Sass Variables
"<style type='text/sass'>
$text-color: red;
.header{
text-align: center;
}
.blog-post, h2 {
color: $text-color;
}
</style>"
Nest CSS with Sass
" .blog-post {
h1 {
text-align: center;
color: blue;
}
p {
font-size: 20px;
}
}"
Create Reusable CSS with Mixins
"<style type='text/sass'>
@mixin border-radius($radius){
-webkit-border-radius:$radius;
-moz-border-radius:$radius;
-ms-border-radius:$radius;
border-radius: $radius;
}
#awesome {
@include border-radius(15px);
width: 150px;
height: 150px;
background-color: green;
}
</style>"
Use @if and @else to Add Logic To Your Styles
"<style type='text/sass'>
@mixin border-stroke($val){
@if $val==light{ border:1px solid black;}
@else if $val==medium{border:3px solid black;}
@else if $val==heavy{border:6px solid black;}
@else{border:none;}
}
#box {
width: 150px;
height: 150px;
background-color: red;
@include border-stroke(medium);
}
</style>"
Use @for to Create a Sass Loop
"<style type='text/sass'>
@for $j from 1 through 6{
.text-#{$j}{
font-size: 10px*$j;
}
}
</style>"
Use @each to Map Over Items in a List
"<style type='text/sass'>
@each $color in blue,black,red{
.#{$color}-bg{background-color:$color;}
}
div {
height: 200px;
width: 200px;
}
</style>"
Apply a Style Until a Condition is Met with @while
"<style type='text/sass'>
$x: 1;
@while $x < 11 {
.text-#{$x} { font-size: 5px * $x;}
$x: $x + 1;
}
</style>"
Split Your Styles into Smaller Chunks with Partials
"@import 'variables'"
Extend One Set of CSS Styles to Another Element
"<style type='text/sass'>
h3{
text-align: center;
}
.info{
width: 200px;
border: 1px solid black;
margin: 0 auto;
}
.info-important{
@extend .info;
background-color: magenta;
}
</style>"
Nhận xét
Đăng nhận xét