Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Responsive Web Design

You're reading from   Mastering Responsive Web Design Push your HTML and CSS skills to the limit and build professional grade, responsive websites

Arrow left icon
Product type Paperback
Published in Aug 2015
Publisher
ISBN-13 9781783550234
Length 334 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Ricardo Zea Ricardo Zea
Author Profile Icon Ricardo Zea
Ricardo Zea
Arrow right icon
View More author details
Toc

Table of Contents (10) Chapters Close

Preface 1. Harness the Power of Sass for Responsive Web Design FREE CHAPTER 2. Marking Our Content with HTML5 3. Mobile-first or Desktop-first? 4. CSS Grids, CSS Frameworks, UI Kits, and Flexbox for RWD 5. Designing Small UIs Driven by Large Finger 6. Working with Images and Videos in Responsive Web Design 7. Meaningful Typography for Responsive Web Design 8. Responsive E-mails Index

How does Sass work?

Knowing how Sass works is a matter of understanding several basic technological concepts:

  1. Sass can be based on two different technologies: Ruby or LibSass. In this book, we're going to use Sass based on Ruby.
  2. Sass is a Ruby gem. Gems are packages for use in Ruby. A Ruby gem is a software that runs only on Ruby. Ruby is a programming language, just like PHP, .NET, Java, and so on.
  3. We can make Sass run via the command line, but we can also run Sass with a third-party application, making the use of the command line unnecessary.
  4. Sass is a programming/scripting language used to create CSS.
  5. CSS is a very repetitive language. Sass allows authors to optimize those repetitive tasks and create CSS faster and more efficiently.
  6. Part of the Sass workflow is when Sass is watching an SCSS file, for example, book-styles.scss. When it detects a change in that SCSS file, it then compiles it into a CSS file book-styles.css.

Tip

Watching an SCSS file means that the Sass watcher is running in the background looking over the SCSS file(s) for any changes.

Installing Sass

Here are the steps we're going to follow:

  1. Download the Ruby installer
  2. Open the command line
  3. Install the Sass gem

Downloading the Ruby installer

Windows: Download the Ruby installer from the following link:

http://rubyinstaller.org/downloads/

Mac: Ruby comes preinstalled on all Macs, so there's no need to download anything.

Opening the command line

Windows and Mac: Open the command line.

Tip

Windows Tip!

Press Windows + R, type CMD, and then press Enter.

Opening the command line

Installing the Sass gem

Type the following command into the command prompt (it doesn't matter which folder you're in):

Windows, use the following command:

gem install sass

Mac, use the following command:

sudo gem install sass
Installing the Sass gem

It'll take a few seconds to install Sass.

Tip

At the time of writing, the latest version of Sass was 3.4.14. The version/revisions might be different by the time the book comes out.

That's it! Sass is now installed on your machine.

Using Sass

What I'm about to show you is completely different to what any other Sass tutorial out there tells you to do. Most of those tutorials complicate things too much. This is the simplest way to use Sass you'll ever read.

The following screenshots are on Windows, but the process can be applied exactly the same regardless of platform.

In the following steps, you will see examples of how the necessary folders and files look after being created, not how to create them:

  1. Create a /Demo folder anywhere on your drive:
    Using Sass
  2. Inside that folder, create two subfolders, /css and /scss:
    Using Sass
  3. Create a .scss file. Go into the /scss folder and create a file called styles.scss:
    Using Sass

    Tip

    Notice the file extension .scss? This is your Sass file. Yes, right now there's nothing in it, it's empty.

  4. Go back to the command line for a minute and follow these steps:
    1. In the command line, type cd <space>
    2. A space after cd means Change Directory. From your file manager, drag and drop the /Demo folder into the command prompt/terminal window and press Enter.
      Using Sass
    3. You should be in the /Demo folder now.
    Using Sass
  5. Make Sass watch your /scss and /css folders by typing this in the command line:
    sass --watch scss:css­
    
  6. Make Sass watch the /scss and /css folders.
    Using Sass

    That's it! You are now using Sass!

    Tip

    The --watch flag tells Sass to pay attention to the /scss and /css folders so that when we make a change to a .scss file (in our case, styles.scss), Sass will detect the change and compile the SCSS into the final CSS file we're going to use in our website or app.

  7. Edit the .scss file and watch Sass compile it into a .css file:
    1. Open your text editor (I use Sublime Text).
    2. Open the styles.scss file.
    3. Add some CSS to it.
    4. Save the styles.scss file.
    5. From your command line/terminal, verify that the compiling was successful.
    6. Open your styles.css file and enjoy your new creation.
    Using Sass
You have been reading a chapter from
Mastering Responsive Web Design
Published in: Aug 2015
Publisher:
ISBN-13: 9781783550234
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime