In this course, we’ll start with regular CSS, and quickly layer on new capabilities and tools that will change the way you think about your app’s styles. Quickly, after moving on from the basics, we’ll start to see how style can be parameterized and re-used, avoiding repetition and redundancy, while keeping everything readable and maintainable.
Next, we’ll look at directives that bring imperative code concepts into stylesheets, like looping, conditional blocks and more. Finally, we’ll experiment with building our own Sass extension, where we can add new vocabulary and capabilities to the way we express styles.
Sass FundamentalsThe preprocessor revolution
We'll look at some of the common CSS pitfalls that motivated the invention of these technologies, and highlight how much easier things become in the Sass world.
Sass FundamentalsStylish Tools
When it comes to transforming Sass files to CSS, we have a few options. We'll learn about options you can use from the command line, and in a node build tool.
Sass FundamentalsEXERCISE 1 - Using the Sass CLI
Build a shell script that transforms a Scss file into two CSS files: one that's human-friendly for a development environment, and one that's smaller for a production environment. How much of a file size savings did we get for this optimization?
Sass FundamentalsNested & Modular Styles
Partials and the
@importdirective allow us to write stylesheets in a modular and maintainable way. We'll look at the pitfalls of the CSS
@importat-rule, and how Sass provides similar capabilities while addressing some common problems.
Sass FundamentalsExercise 2 - DRY Styles
Sticking to "the inception rule", refactor the Scss file you're given to take advantage of Sass nesting features
Sass FundamentalsExercise 3 - Partials and import
@importdirective, combined with partials allow us to break our stylesheets up into modular units. Make all of your failing tests pass, while avoiding any new redundancy.
Sass FundamentalsSassScript: Variables & Operators
Being able to store and re-use values is a game-changer, in terms of reducing redundancy and improving consistency and maintainability throughout your styles. We'll discuss variable best practices, unit conversions and more!
Sass FundamentalsEXERCISE 4 - Variable Math
Make the failing tests pass, by substituting literal values with SassScript expressions. Keep units in mind, and avoid any fudge factors!
Break for lunch.
Sass FundamentalsBuilt-in Functions
Sass has a treasure trove of built-in functions that allow us to expressively manipulate colors, numbers, lists, maps and more! We’ll look at what’s available, and then learn some best practices for practical and maintainable usage.
Mixins allow us to re-use basic or parameterized chunks of style, via the
@extenddirective, without having to introduce tons of complexity into your HTML.
Sass FundamentalsEXERCISE 5 - DRY Buttons
.buttonclass in our app is available in a variety of colors, but there's a lot of repeated style between them. Using a combination of nested styles, color functions and mixins, design a means of generating a button of an arbitrary color (or set of colors).
Sass FundamentalsExtensible Styles
@extenddirective is a powerful tool, we can use to "inherit" styles, but if over-used it has the potential to increase the size and complexity of the compiled CSS. We'll take a look at all this feature of Sass can do, some limitations as to where and how it can be applied, and some patterns for responsible use.
Sass FundamentalsEXERCISE 6 - Links as Buttons
Many UI frameworks represent links with a particular class and the
<button>with similar visual styles. Refactor and make use of the
@extenddirective to accomplish this. Your change must result in a net reduction in LOC of Scss, and no more than a 2% increase in compressed CSS filesize.
Sass FundamentalsControl Directives
One of the most powerful aspects of Sass is the ability to add control flow to our sales. With the
@whiledirectives, we can create powerful, concise and expressive styles, which are far easier to maintain and tweak than their CSS counterparts.
Sass FundamentalsEXERCISE 7 - Grid Generator
Using control directives, build a mixin that generates a grid with an arbitrary number of columns. As an extra challenge, try to make the grid responsive!
Sass FundamentalsWrap Up
We'll recap everything we've learned today