THE BIGGEST DIFFERENCE BETWEEN EXTEND AND MIXIN -
!WHEN YOU ADD MIXIN TO A CLASS, IT COPIES MIXIN'S CONTENT INTO A CLASS!
!WHEN YOU ADD AN EXTEND TO A CLASS, IT COPIES A NAME OF ALL CLASSES WITH THAT EXTEND AND CREATES A NEW BLOCK OF CSS VALUES!
EXTENDS SHOULD WORK WITH RELATED ELEMENTS ONLY
<nav>
<ul class="navigation"
<li><a href="#">About Us</a></li>
<li><a href="#">Pricing</a></li>
<li><a href="#">Contact</a></li>
</ul>
<div class="button">
<a class="btn-main" href="#">Sign Up</a>
<a class="btn-hot" href="#">Get a Quote</a>
</div>
</nav>
* {
margin: 0;
padding: 0;
}
$color-primary: #f9ed69;
$color-secondary: #f08a5d;
$color-tertiary: #b83b5e;
$color-text-dark: #333;
$color-text-light: #eee;
$width-button: 150px;
@mixin clearfix {
&::after { //fixes collapsed element (floats)//
content: "";
clear: both;
display: table;
}
}
@mixin style-link-text($col) {
text-decoration: none;
text-transform: uppercase;
color: $col;
}
@function divide($a, $b) {
@return ($a / $b) * 1px;
}
nav {
margin:divide(60,2); //30px
background-color: $color-primary;
@include clearfix;
}
.navigation {
list-style:none;
float: left;
li {
display: inline-block;
margin-left: 30px;
&:first-child {
margin: 0;
}
a:link {
@include style-link-text($color-text-dark);
}
}
}
.button {
float: right;
}
%btn-placeholder {
padding: 10px;
display: inline-block;
text-align: center;
border-radius: 100px;
width: $width-button;
@include style-link-text($color-text-light);
}
.btn-main {
&:link {
@extend %btn-placeholder;
background-color: $color-secondary;
}
&:hover {
background-color: darken($color-secondary, 15%); //inbuilt sass function
}
}
.btn-hot {
&:link {
@extend %btn-placeholder;
background-color: $color-tertiary;
}
&:hover {
background-color: lighten($color-tertiary, 15%); //inbuilt sass function
}
}