SASS and SCSS (Sassy CSS)
SASS-> Systematically Awesome Style SheetsSCSS-> Sassy Cascading Style Sheets
Nested Properties
- SCSS
- CSS
$full-width: 100%;
.mobile-nav__items {
width: 90%;
height: $full-width;
display: flex;
flex: {
direction: column;
wrap: nowrap;
}
}
.mobile-nav__items {
width: 90%;
height: 100%;
display: flex;
flex-direction: column;
flex-wrap: nowrap;
}
Lists & Maps
- SCSS
- CSS
$border-size: 1.5px;
// map
$color: (green-dark: #0e4f1f, red-bright: #ff1b68);
// List
$border-default: $border-size solid map-get($color, green-dark);
.button {
background: map-get($color, red-bright);
color: white;
font: inherit;
border: $border-default;
padding: .5rem;
border-radius: 8px;
font-weight: bold;
cursor: pointer;
}
.button {
background: #ff1b68;
color: white;
font: inherit;
border: 1.5px solid #0e4f1f;
padding: 0.5rem;
border-radius: 8px;
font-weight: bold;
cursor: pointer;
}
Built-in functions
- SCSS
- CSS
$dark-green: #0e4f1f;
.background {
background: lighten($dark-green, 72%);
}
.background {
background: #d5f8de;
}
Arithmetic operations in SASS/SCSS
- SCSS
- CSS
$border-size: 1rem;
.maths {
border-radius: $border-size * 3;
}
.maths {
border-radius: 3rem;
}
Media query in SASS/SCSS
- SCSS
- CSS
.container {
display: flex;
flex-direction: row;
font-size: 15px;
@media (min-width: 40rem) {
flex-direction: column;
font-size: 10px;
}
}
.container {
display: flex;
flex-direction: row;
font-size: 15px;
}
@media (min-width: 40rem) {
.container {
flex-direction: column;
font-size: 10px;
}
}
Inheritance in SCSS/SASS
- SCSS
- CSS
$color: (green-dark: #0e4f1f, red-bright: #ff1b68);
$border-size: 1.5px;
.sass-section {
font-family: 'Montserrat', sans-serif;
border: $border-size solid map-get($color, green-dark);
width: 50px;
}
.box1 {
@extend .sass-section;
height: 60px;
}
.box2 {
@extend .sass-section;
height: 70px;
}
.sass-section, .box1, .box2 {
font-family: 'Montserrat', sans-serif;
border: 1.5px solid #0e4f1f;
width: 50px;
}
.box1 {
height: 60px;
}
.box2 {
height: 70px;
}
/* OR */
.box1 {
font-family: 'Montserrat', sans-serif;
border: 1.5px solid #0e4f1f;
width: 50px;
height: 60px;
}
.box2 {
font-family: 'Montserrat', sans-serif;
border: 1.5px solid #0e4f1f;
width: 50px;
height: 70px;
}
Mixins
- SCSS
- CSS
$dark-green: #0e4f1f;
// mixin without arguments
@mixin display-flex() {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.container {
@include display-flex();
flex-direction: column;
}
.container {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
flex-direction: column;
}
- SCSS
- CSS
$dark-green: #0e4f1f;
// mixin with arguments
@mixin media-min-width($width) {
@media (min-width: $width) {
border: 2px solid green;
@content;
}
}
body {
background: $dark-green;
font-size: 15px;
@include media-min-width(40rem) {
font-family: 'Montserrat', sans-serif;
font-size: 10px;
}
}
body {
background: #0e4f1f;
font-size: 15px;
}
@media (min-width: 40rem) {
body {
border: 2px solid green;
font-family: 'Montserrat', sans-serif;
font-size: 10px;
}
}