mirror of
https://github.com/jbranchaud/til
synced 2026-01-04 23:58:01 +00:00
Add Dry Up SCSS With Mixins as a css til
This commit is contained in:
@@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
|||||||
For a steady stream of TILs from a variety of rocketeers, checkout
|
For a steady stream of TILs from a variety of rocketeers, checkout
|
||||||
[til.hashrocket.com](https://til.hashrocket.com/).
|
[til.hashrocket.com](https://til.hashrocket.com/).
|
||||||
|
|
||||||
_584 TILs and counting..._
|
_585 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -80,6 +80,7 @@ _584 TILs and counting..._
|
|||||||
|
|
||||||
### CSS
|
### CSS
|
||||||
|
|
||||||
|
- [Dry Up SCSS With Mixins](css/dry-up-scss-with-mixins.md)
|
||||||
- [Lighten And Darken With CSS Brightness Filter](css/lighten-and-darken-with-css-brightness-filter.md)
|
- [Lighten And Darken With CSS Brightness Filter](css/lighten-and-darken-with-css-brightness-filter.md)
|
||||||
- [Lighten And Darken With SCSS](css/lighten-and-darken-with-scss.md)
|
- [Lighten And Darken With SCSS](css/lighten-and-darken-with-scss.md)
|
||||||
|
|
||||||
|
|||||||
59
css/dry-up-scss-with-mixins.md
Normal file
59
css/dry-up-scss-with-mixins.md
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
# Dry Up SCSS With Mixins
|
||||||
|
|
||||||
|
If you have a similar chunk of styling that is being duplicated across your
|
||||||
|
CSS, you'd probably like to dry it up to reduce the pain of maintaining it.
|
||||||
|
Mixins provide one way of dealing with this problem.
|
||||||
|
|
||||||
|
First, declare a named mixin of the styles that you are trying to dry up.
|
||||||
|
|
||||||
|
```css
|
||||||
|
@mixin navigation {
|
||||||
|
nav {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-around;
|
||||||
|
|
||||||
|
ul {
|
||||||
|
list-style: none;
|
||||||
|
|
||||||
|
li a {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Then, this mixin can be _included_ wherever it is needed.
|
||||||
|
|
||||||
|
```css
|
||||||
|
div.base-nav {
|
||||||
|
@include nav;
|
||||||
|
background-color: #fff;
|
||||||
|
color: #444;
|
||||||
|
|
||||||
|
nav ul {
|
||||||
|
li a:hover {
|
||||||
|
color: #222;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
div.admin-nav {
|
||||||
|
@include nav;
|
||||||
|
background-color: #000;
|
||||||
|
color: #fff;
|
||||||
|
|
||||||
|
nav ul {
|
||||||
|
li a:hover {
|
||||||
|
color: #ddd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Any subsequent changes to the core navigation styling only need to be made
|
||||||
|
in one place, the mixin.
|
||||||
|
|
||||||
|
[source](http://sass-lang.com/guide)
|
||||||
|
|
||||||
|
h/t Dorian Karter
|
||||||
Reference in New Issue
Block a user