Book Image

Sass Essentials

By : Alex Libby
Book Image

Sass Essentials

By: Alex Libby

Overview of this book

<p>Sass is a professional grade CSS extension language known for its stability and versatility in the field of web design. It introduces new concepts to CSS, such as variables and nesting, that allow users to speed up their workflows and make their code more dynamic.</p> <p>Sass Essentials is a fast-paced, hands-on guide that breaks down the mysteries of preprocessing CSS styles using the Sass preprocessor and shows you how you can apply simple techniques to quickly and efficiently create CSS style sheets.</p> <p>With this book, you will dive in and familiarize yourself with some popular directives and see how, with some care and planning, they can prove to be really powerful tools to use in Sass.</p>
Table of Contents (12 chapters)

Preface

Picture this scene—you consider yourself pretty au fait with developing CSS styling; you've produced some stunning work over the years, spending time carefully crafting styles for demanding clients.

A colleague starts to band this word "Sass" around the office—you soon hear others talk of this "Sass" on Twitter and begin to wonder what it's all about.

Well, fear no more—welcome to the world of Sass! Throughout the course of this book, we'll delve into the world of CSS preprocessing, where we will explore tips and tricks that can help you make your CSS development more efficient, using Sass. Of course, you're probably wondering how; all will be revealed. Consider this as a taster though—how often have you spent time choosing colors for buttons only to find out that the client doesn't like the color scheme.

Sound familiar? I'll bet the answer is yes. In the next few pages, I will show you the tricks you need to know to create a color scheme from a single color. Let's just say that should you find out that your clients want the color changed, long evenings of changing code will become a thing of the past.

Let's dive in and start our journey through the world of Sass.

What this book covers

Chapter 1, Introducing Sass, takes you through the journey of Sass and discusses its essentials. This chapter will introduce Sass, tell you how to install it, and explore how it will make your development workflow smarter and more efficient, ultimately saving you valuable time. It will also help you create a simple layout and show you how to use Sass to compile the code to produce valid CSS.

Chapter 2, Creating Variables and Mixins, explores a key facet of Sass in the form of using variables. It discusses how editing one value can automatically update a whole series of rules at a single stroke. Just imagine altering the font sizes for your website in one go by simply editing one number!

Chapter 3, Building Functions, Operations, and Nested Styles, talks about how to use functions and operators to construct an entire site from just a handful of variables. We will also touch on nesting styles to help make code easier to read and maintain.

Chapter 4, Directing Sass, takes a look at another key element of Sass in the form of directives. It provides information on how to use some of the more popular options, such as @extend or @media. These will be used to a great effect in a series of demos, which quickly illustrates how careful use of these directives can have a significant positive effect on our code.

Chapter 5, Incorporating Sass into Projects, examines how to apply some of the tips and tricks we have covered throughout the book into more practical uses. It talks about several popular frameworks, such as Bootstrap, WordPress, and CSS grids. This chapter also shows you how Sass can be used to great effect to help construct sites, while reducing the amount of code we need to write.

What you need for this book

All you need to work through most of the examples in this book is a simple text or code editor, Internet access, and a web browser. I recommend installing Sublime Text, preferably version 3. It has an excellent add-in package system that works well; we will make use of this at various stages throughout the book.

Some of the examples make use of additional software, such as Node or Grunt—details are included in the appropriate chapter along with links to download the application from source.

Who this book is for

The book is for frontend developers who want to quickly get up to speed with using Sass. It will make writing CSS styles more efficient. To get the most out of this book, you should have a good working knowledge of HTML, CSS, and jQuery; we will use a little of the latter later in the book.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We'll start by extracting the relevant files from the code download for this book—for this demo, we'll need clicktoggle.scss and clicktoggle.html."

A block of code is set as follows:

$baseWidth: 800px;
$mainWidth: round($baseWidth / 1.618);
$sidebarWidth: round($baseWidth * 0.382);

@function calculateRem($size) {
  $remSize: $size / 16px;
  @return $remSize * 1rem;
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

min-height: 100px;

#container
  //media query - screen and 320px
  @include breakpoint($phone) {
    #container { max-width: 800px; background: #ccc; box-
      shadow: none; margin: 0 auto; }
  }

Any command-line input or output is written as follows:

npm install

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Once completed, click on Finish."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from: https://www.packtpub.com/sites/default/files/downloads/4301OS_Graphics.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.