Book Image

Mastering Sass

By : Luke Watts
Book Image

Mastering Sass

By: Luke Watts

Overview of this book

CSS and Sass add elegance and excellence to the basic language, and consist of a CSS-compatible syntax that allows you to use variables, nested rules, mixins, inline imports, and much more. This book will start with an overview of the features in Sass and Compass, most of which you'll already be familiar; however, this will ensure you know what’s expected as the book goes deeper into Sass and Compass. Next you will learn CSS and HTML concepts that are vital to a good Sass workflow. After all, Sass exists to simplify writing CSS, but it won’t teach you how to make clean, scalable, reusable CSS. For that, you need to understand some basic concepts of OOCSS, SMACCS, and Atomic Design. Once you’ve brushed up on the important concepts, it’s time to write some Sass. Mainly you’ll write a few functions and mixins that really leverage control flow using @if / @else loops and you’ll learn how to figure out when and why things are going wrong before they bring you to a stop. Moving further, you’ll learn how to use @debug, @warn and @error to properly handle errors. You’ll also learn about Gulp and how to use it to automate your workflow and reduce your repetitive tasks. And finally you’ll learn about sourcemaps. With sourcemaps, you’ll be able to write, debug, and view your Sass and Compass all from within the browser. It’ll even LiveReload too! As a bonus, you’ll take a look at that funky Flexbox, currently all the rage! You’ll learn how powerful and flexible it really is, and how you can use it with Compass. Best of all, it falls back very gracefully indeed! In fact, you’ll be able to apply it to any existing project without having to change a line of the original CSS.
Table of Contents (16 chapters)
Mastering Sass
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface

Data types in Sass


If we look at the base-font-sizes-calc() function, we know it takes in a font family and then calculates the correct value to return. However, what if someone passed in a number? It's reasonable to assume something called base-font-sizes-calc() deals with numbers, right? So we need to make sure we are only getting a string, and if not we need to tell the user this function needs a string which is the font-family and not a number.

Sass has 7 main data types (8 if you count arg list):

  • string [unquoted, "quoted string", 'single quoted string']

  • number [1, 0.5, 1rem, 5px, 2em]

  • bool [true, false]

  • null [null]

  • list [(1, 2, 3, 4), ("one" "two" "three")]

  • map [(h1: 2rem, h2: 1.5rem, h3: 1.17rem)]

  • color [#bada55, red, hsl(10, 30%, 50%), rgb(255, 160, 80)]

The way you check for a specific type is with the Sass function type-of(). So now we can update our function to perform this check with a simple ifelse statement:

// mastering-sass/ch02/scss/helpers/_functions.scss 
@function...