Find file
Fetching contributors…
Cannot retrieve contributors at this time
247 lines (115 sloc) 12.1 KB
<!doctype html>
<!--[if lt IE 9]> <html class="no-js oldie" lang="en"> <![endif]-->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>An Introduction to Sass and Compass | Divya Manian</title>
<meta name="author" content="Divya Manian">
<meta name="description" content="This is paraphrased from my presentation at Refresh Seattle on March 25th. You can view the presentation or download the slides from Github. I &hellip;">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="canonical" href="">
<link href="/stylesheets/screen.css" rel="stylesheet">
<link href="" rel="alternate" title="Subscribe" type="application/atom+xml">
<link href="" rel="alternate" title="Subscribe to Web Development updates" type="application/atom+xml">
<body >
<div class="container">
<div class="content">
<header role="banner"> <h1><a href="/">Divya Manian</a></h1>
<h2><a class="twitter" href="">twitter</a> <a class="rss" href="">RSS Feed</a> <a class="youtube" href="">Youtube Channel</a> <a class="github" href="">Github</a></h2>
<nav class="sitenav"><a href="/">Home</a>
<a href="/archives">Archives</a>
<a href="/about.html">About</a>
<nav class="article">
<a class="previous" href="/dom-ecmascript-and-other-puzzles.html" title="DOM, ECMAScript and other puzzles">&#x276C;</a>
<a class="next" href="/book-reviews-for-mar-2010.html" title="Book Reviews for Mar 2010">&#x276D;</a>
<time datetime="2010-03-28T00:00:00+05:30" pubdate><span class='month'>Mar</span> <span class='day'>28</span> <span class='year'>2010</span></time>
<h1 class="entry-title"><a href="/an-introduction-to-sass-and-compass.html">An Introduction to Sass and Compass</a></h1>
<div class="entry-content"><p><em>This is paraphrased from my presentation at <a href="">Refresh Seattle</a> on March 25th. You can <a href="/refresh-seattle/">view the presentation</a> or download the <a href="">slides from Github</a>.</em></p>
<p>I stumbled onto Sass last January, when I was struggling with large style sheets of several websites in various states of development.</p>
<p>I work on large, high-traffic websites mostly and maintain at least 10 such sites at any given time. A website that I have not worked on for 2 years or more would suddenly require updates, and I would have to re-learn (what I consider) atrocious coding practices of my old self. Sometimes, these websites acquire new designs based on seasonal promotions. It did not help that most of these websites had more than 5000 lines of CSS.</p>
<p>I started looking for solutions to my CSS maintenance woes. I briefly considered <a href="">CSS frameworks</a>, but these dump a set of properties irrespective of their usage. I also looked at <a href="">LessCSS</a> whose every-rule-is-a-reusable-snippet looked like an even worse maintenance nightmare. Sass looked most promising. I took a chance and am glad to have done so. </p>
<p>Sass stands for Syntactically Awesome Stylesheets. It is written in ruby and has command line tools to convert Sass to CSS, or CSS to Sass. It also includes a “watch” utility that watches a certain folder which contains the Sass files for any changes and automatically compiles updated Sass files to their respective CSS files. </p>
<p>Sass has a different syntax as compared to CSS. Here is a sample Sass file:</p>
<pre>!bordercolor = #000
border = 1px "solid" !bordercolor
padding: 1px</pre>
<p>This is how the generated CSS looks:</p>
<pre><code>div.content { border: 1px solid #000; }
div.content h2 { padding: 1px; }</code></pre>
<p>Sass is not white-space agnostic, and you need to be careful with the indentation as that decides which parent selector the child selector belongs to. If you would like to learn how to use this in detail, head over to the <a href="">Official Sass tutorial</a>.</p>
<p>Sass has lots of features, most of which can be found in <a href="">the reference documentation</a>. My favourite elements of Sass are: <a href="">Mixins</a>, <a href="">Variables</a>, <a href="">Sass comments</a>, <a href="">@import directive</a>, <a href="">Functions</a>, <a href="">If/For/While directives</a>, and <a href="">Output Style formatting</a>. Several more are undocumented, or are better explained in the <a href="">mailing list</a>.</p>
<p><a href="">Compass</a> is a framework built on Sass that makes it easier to use it stand alone on non-ruby projects. Several features that have made into the latest releases of Sass were first created in Compass by <a href="">Chris Eppstein</a>. Compass makes available many <a href="">CSS Frameworks</a> like Blueprint, YUI, and <a href="">Susy</a> for use in your Sass files. There is an <a href="">hour-long introduction to Compass</a> which is definitely worth your time if you are looking to use Sass/Compass in the long-term.</p>
<p>Recently, <a href="">Nathan Weizenbaum</a>, the maintainer of Sass, has released <a href="">FireSass</a>, a firebug plugin that renders the line number and the Sass filename from which a selected HTML element gains its properties instead of the line number and the CSS filename. This makes debugging your stylesheet lot easier if you use Sass primarily.</p>
<p>Nathan is also working on getting Sass 3 beta version out live. It will include a new format called <a href="">SCSS</a> which replicates the CSS syntax (like LessCSS).</p>
<p>While Sass has a lot of tools, and is quite powerful, it is not necessary that you have to use it. I would recommend you use it only if you:</p>
<li>Have large CSS files that you intend to maintain over a long period of time (in which case, converting them to multiple Sass files is a good idea).
<li>Deal with several websites with markedly different style sheets but would like to create a common library of styles that you can invoke when necessary without writing additional code.</li>
<li>Write CSS for a living.</li>
<p>Sass is not <em>the</em> answer for your CSS ills. You still need to know how to write CSS and your Sass file can be a noodlesoup of unmaintainable nested selectors if you are not mindful. </p>
<p>If you use Textmate, there is a <a href="">Ruby Sass Textmate bundle</a> to make it easier to type Sass syntax. There is also a <a href="">Compass bundle</a> that lets you look up mixins available in Compass. </p>
<p class="meta">This post was posted by
<a href="/about.html">Divya Manian</a>
<time datetime="2010-03-28T00:00:00+05:30" pubdate><span class='month'>Mar</span> <span class='day'>28</span> <span class='year'>2010</span></time> in
<span class="categories">
<a class='category' href='/categories/web-development/'>Web Development</a>
. If you would like to update this post, <a href="">please send a pull request</a>.
<div id="disqus_thread" aria-live="polite"><noscript>Please enable JavaScript to view the <a href="">comments powered by Disqus.</a></noscript>
<aside id="articles">
<p><img class="avatar" src="" height=48> <a href="">Divya Manian</a> lives in SF. <a href="/about.html">More about me ❭</a></p>
<h2>Posts on Web Development</h2>
<ul><li><a href="/diversity-in-conferences.html">Diversity in Conferences</a></li><li><a href="/using-decimal-percentage-values-in-responsive-design.html">Using decimal percentage values in responsive design</a></li><li><a href="/using-background-clip-for-text-with-css-fallback.html">Using background clip for text with CSS fallback</a></li><li><a href="/markup-free-icon-fonts-with-unicode-range.html">Markup-free icon fonts using unicode-range</a></li><li><a href="/jscamp-css-next.html">JSCamp: CSS Next</a></li><li><a href="/some-updates.html">Some Updates</a></li><li><a href="/css-object-model.html">CSS Object Model</a></li><li><a href="/fake-bolding-of-web-fonts.html">Fake Bolding of Web Fonts</a></li><li><a href="/html5please-api.html">Html5please API</a></li><li><a href="/html5please.html">html5please</a></li><li><a href="/mustache.html">mustache, hogan, handlebars</a></li><li><a href="/redesign-notes.html">Redesign Notes</a></li><li><a href="/summary-of-various-exciting-css-drafts-and-proposals.html">Summary of various exciting CSS drafts and proposals</a></li><li><a href="/this-revolution-needs-new-revolutionaries.html">This revolution needs new revolutionaries</a></li><li><a href="/some-css-transition-hacks.html">Some CSS Transition hacks</a></li><li><a href="/safe-css-defaults.html">Safe CSS Defaults</a></li><li><a href="/unplugged-2011.html">Unplugged 2011</a></li><li><a href="/bokeh-with-css3-gradients.html">Bokeh with CSS3 Gradients</a></li><li><a href="/making-pure-css3-demos-better.html">Making "Pure CSS3" demos better</a></li><li><a href="/web-opener-at-opera.html">Web Opener at Opera</a></li><li><a class="btn" href="/categories/web-development/">More</a></li></ul>
<footer role="contentinfo"><p>
Copy to your heart’s content 2013 - Divya Manian -
<span class="credit">Powered by <a href="">Octopress</a></span>
<script type="text/javascript">
var disqus_shortname = 'nimbublog';
var disqus_developer = 1;
var disqus_url = '';
var disqus_identifier = '';
(function () {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
<script src="/javascripts/octopress.js"></script>
var _gaq=[['_setAccount','UA-97188-1'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];