30
loading...
This website collects cookies to deliver better user experience
$color: blue;
p {
color: $color;
}
<nav>
<ul>
<li> <a href="#"> Something </a> </li>
<li> <a href="#"> Another thing </a> </li>
</ul>
</nav>
nav {
background-color: blue;
}
nav ul {
list-style: none;
}
nav ul li {
border-right: 1px solid #000;
}
nav ul li a {
text-decoration:none;
}
nav {
background-color: blue;
ul {
list-style: none;
li {
border-right: 1px solid #000;
a {
text-decoration:none;
}
}
}
}
@mixin font-color($color) {
color: $color;
}
p {
@include font-color(blue);
font-size: 15px;
}
p {
color: blue;
font-size: 15px;
}
@if and @else
@mixin draw-border($name) {
@if $name == light-border {
border: 1px solid #000;
}
@else if $name == medium-border {
border: 5px solid #000;
}
@else if $name == dark-border {
border: 10px solid #000;
}
@else {
border: 2px solid #000;
}
}
.mini-container {
@include draw-border(dark-border);
height: 200px;
width: 200px;
background-color: #fff;
}
.mini-container {
border: 10px solid #000;
height: 200px;
width: 200px;
background-color: #fff;
}
draw-border
mixin with three different conditions.@for $size from 1 through 6 {
.text-size-#{$size} {
font-size: 15 * $size px;
}
}
@for $size from 1 to 7 {
.text-size-#{$size} {
font-size: 15 * $size px;
}
}
from 1 through 6
but on the other hand in the second loop, I used from 1 to 7
. #{}
for rendering the $size
variable. And another thing is for this loop SCSS has @for
directive.through
does not exclude the end number from the loop whereas to
excludes the end number from the loop. So now you understand what's the fact about these two loops. The compiled css code should look as below..text-size-1 {
font-size: 15 px; // ( 15 * 1 )
}
.text-size-2 {
font-size: 30 px; // ( 15 * 2 )
}
.text-size-3 {
font-size: 45 px; // ( 15 * 3 )
}
.text-size-4 {
font-size: 60 px; // ( 15 * 4 )
}
.text-size-5 {
font-size: 75 px; // ( 15 * 5 )
}
.text-size-6 {
font-size: 90 px; // ( 15 * 6 )
}
@each $color in red, green, blue {
.text-#{$color} {
color: #{$color};
}
}
// The above code will generate similar css code below
.text-red {
color: red;
}
.text-green {
color: green;
}
.text-blue {
color: blue;
}
$colors: (primary: blue, danger: red, success: green);
@each $key, $color in $colors {
.text-#{$key} {
color: $color;
}
}
// The above code will generate similar css code below
.text-primary {
color: blue;
}
.text-danger {
color: red;
}
.text-success {
color: green;
}
$heading: 1;
@while $heading < 7 {
.heading-#{$heading} {
font-size: 15 * $heading px;
}
$heading: $heading + 1;
}
// The above code will generate similar css code below
.heading-1 {
font-size: 15 px;
}
.heading-2 {
font-size: 30 px;
}
.heading-3 {
font-size: 45 px;
}
.heading-4 {
font-size: 60 px;
}
.heading-5 {
font-size: 75 px;
}
.heading-6 {
font-size: 90 px;
}
$heading < 7
. This means if $heading is less than 7 run the loop._hero.scss
and we want to use the partials into our main.scss
file. So inside the main.scss file the code would be like below.@import 'hero'
@import 'hero'
partials into main.css file we did not put _ in front of the name? Yes, you are right? This _ should not put, we have to remember that._helo.scss
file into the main.scss
file. This is all about partials in SCSS..mini-container
with some property and I want to use all the property of the .mini-container
inside another class named .mini-blue-container
..mini-container {
height: 300px;
width: 300px;
border: 1px solid red;
}
.mini-blue-container {
@extend .mini-container;
background-color: blue;
}
// The compiled code would look something like
.mini-container, .mini-blue-container {
height: 300px;
width: 300px;
border: 1px solid red;
}
.mini-blue-container {
background-color: blue;
}
@extend
feature we reduced our code size and saved time as well.