<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">The Sass Way</title>
  <generator uri="http://effectif.com/nesta">Nesta</generator>
  <id>tag:thesassway.com,2009:/</id>
  
  <link href="http://thesassway.com" rel="alternate" />
  <subtitle type="text">The latest in Sass and Compass &amp; Beginner, Intermediate and Advanced topics</subtitle>
  <updated>2013-05-24T00:00:00+00:00</updated>
  <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/thesassway" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="thesassway" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
    <title>Avoid nested selectors for more modular CSS</title>
    <link href="http://thesassway.com/intermediate/avoid-nested-selectors-for-more-modular-css" rel="alternate" type="text/html" />
    <id>tag:thesassway.com,2013-05-24:/intermediate/avoid-nested-selectors-for-more-modular-css</id>
    <content type="html">&lt;p&gt;We&amp;#8217;ve written before about the dangers of nesting your CSS selectors too deeply. The &lt;a href='http://thesassway.com/beginner/the-inception-rule'&gt;Inception Rule&lt;/a&gt; is a good one for getting you to avoid some mangled CSS selectors. But there&amp;#8217;s actually a lot of benefit to taking this concept a couple of steps farther. What happens when you avoid nesting for almost all of your major selectors?&lt;/p&gt;

&lt;h2 id='contextual_selectors'&gt;Contextual selectors&lt;/h2&gt;

&lt;p&gt;First, let&amp;#8217;s talk about why this might be a good idea. One of the most powerful things about CSS is the ability to style elements differently based on different contexts. For example:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::scss&amp;#x000A;.post {&amp;#x000A;  margin: 2em 0;&amp;#x000A;&amp;#x000A;  .title {&amp;#x000A;    font-size: 2em;&amp;#x000A;    font-weight: normal;&amp;#x000A;  }&amp;#x000A;}&amp;#x000A;&amp;#x000A;.sidebar .post {&amp;#x000A;  margin: 1em 0;&amp;#x000A;&amp;#x000A;  .title {&amp;#x000A;    font-size: 1.2em;&amp;#x000A;    font-weight: bold;&amp;#x000A;  }&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The code above is a basic example of how you might style a blog post differently based on whether it is within the sidebar or not.&lt;/p&gt;

&lt;p&gt;At first this kind of contextual power may seem like a very good idea. You can use the same HTML in the sidebar of your site as you do in the main body of the site and get very different stylistic results.&lt;/p&gt;

&lt;p&gt;But what happens when you want to use the styles that you&amp;#8217;ve written for posts in your sidebar in an archive index or something similar? Whoops! Our contextual code will have to be updated for the new context.&lt;/p&gt;

&lt;p&gt;Now Sass provides many powerful tools that can make sharing styles in different contexts easy, but this often comes with an added cost of complexity. If you care at all about writing maintainable code you will avoid complexity at all costs.&lt;/p&gt;

&lt;h2 id='a_more_modular_way'&gt;A more modular way&lt;/h2&gt;

&lt;p&gt;Let&amp;#8217;s write these styles in a more modular way:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::scss&amp;#x000A;.post {&amp;#x000A;  margin: 2em;&amp;#x000A;&amp;#x000A;  .title {&amp;#x000A;    font-size: 2em;&amp;#x000A;    font-weight: normal;&amp;#x000A;  }&amp;#x000A;}&amp;#x000A;&amp;#x000A;.summary {&amp;#x000A;  margin: 2em;&amp;#x000A;&amp;#x000A;  .title {&amp;#x000A;    font-size: 1.2em;&amp;#x000A;    font-wieght: bold;&amp;#x000A;  }&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Hot dog! That&amp;#8217;s better. Now we&amp;#8217;ve made our rules more generic and aren&amp;#8217;t styling as much on context. We&amp;#8217;ve got two separate CSS &amp;#8220;modules&amp;#8221; now. Post and summary. Summary can be used for sidebar items or in our archive index.&lt;/p&gt;

&lt;p&gt;But we can improve this code further. The title class is still used in a contextual way. All it takes is for someone to declare a more generic title rule and your styles can be thrown off.&lt;/p&gt;

&lt;h2 id='clashing_worlds'&gt;Clashing worlds&lt;/h2&gt;

&lt;p&gt;Suppose you decided to make a page title, and declared the rule like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::css&amp;#x000A;.title {&amp;#x000A;  font-size: 3em;&amp;#x000A;  font-weight: bold;&amp;#x000A;  color: red;&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Without thinking about how you&amp;#8217;ve used title already in other contexts you&amp;#8217;ve created a rule that will effect all other elements that also use a class of &amp;#8220;title&amp;#8221;. Now this example is a bit contrived, but in the real world this kind of style clash is common. On projects I&amp;#8217;ve worked on in the past that use this style of coding it is a common occurrence that someone adds a new rule somewhere else that blows out styles in other contexts. On large projects these kinds of &amp;#8220;bugs&amp;#8221; can be hard to catch before code is moved into production.&lt;/p&gt;

&lt;p&gt;So how can we simplify our code and at the same time add clarity? Like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::css&amp;#x000A;.page-title {&amp;#x000A;  font-size: 3em;&amp;#x000A;  font-weight: bold;&amp;#x000A;  color: red;&amp;#x000A;}&amp;#x000A;&amp;#x000A;// Posts&amp;#x000A;.post {&amp;#x000A;  margin: 2em 0;&amp;#x000A;}&amp;#x000A;.post-title {&amp;#x000A;  font-size: 2em;&amp;#x000A;  font-weight: normal;&amp;#x000A;}&amp;#x000A;&amp;#x000A;// Summaries&amp;#x000A;.summary {&amp;#x000A;  margin: 1em 0;&amp;#x000A;}&amp;#x000A;.summary-title {&amp;#x000A;  font-size: 1.2em;&amp;#x000A;  font-weight: bold;&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Ah! Much better! This minimizes the chance that other rules will clash with the ones we&amp;#8217;ve just defined and helps ensure that our CSS modules will look the same in any context.&lt;/p&gt;

&lt;h2 id='context_and_modularity'&gt;Context and modularity&lt;/h2&gt;

&lt;p&gt;The key word here is &lt;strong&gt;context&lt;/strong&gt;. If you value modularity you will strive to avoid contextual styles. There are times when context can be useful. Responsive designs and themes often require them. But you should be very intentional when choosing to use contextual styles. If you use them without thinking you may find that your code is extremely hard to maintain and accidental bugs surface more regularly than you would like.&lt;/p&gt;

&lt;p&gt;It&amp;#8217;s also worth noting that if you find yourself using nesting regularly, you should consider if removing it could simplify your code.&lt;/p&gt;

&lt;h2 id='conclusion'&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Hopefully you don&amp;#8217;t find these ideas too controversial. If you are interested in learning more about modular CSS I highly recommend taking a look at Jonathan Snook&amp;#8217;s &lt;a href='http://smacss.com'&gt;ebook on the subject&lt;/a&gt; and following Harry Roberts over at &lt;a href='http://csswizardry.com'&gt;CSS Wizardry&lt;/a&gt;.&lt;/p&gt;</content>
    <published>2013-05-24T00:00:00+00:00</published>
    <updated>2013-05-24T00:00:00+00:00</updated>
    <category term="guides" />
    <category term="intermediate" />
    <category term="john-w-long" />
  </entry>
  <entry>
    <title>How to structure a Sass project</title>
    <link href="http://thesassway.com/beginner/how-to-structure-a-sass-project" rel="alternate" type="text/html" />
    <id>tag:thesassway.com,2013-04-03:/beginner/how-to-structure-a-sass-project</id>
    <content type="html">&lt;p&gt;One of the most useful features of Sass is being able to separate your stylesheets into separate files. You can then use the &lt;code&gt;@import&lt;/code&gt; directive to include the source of your individual files into one master stylesheet.&lt;/p&gt;

&lt;p&gt;But how should you structure your Sass projects? Is there a standard way of separating out your CSS files?&lt;/p&gt;

&lt;h2 id='basic_directory_structure'&gt;Basic directory structure&lt;/h2&gt;

&lt;p&gt;I like to layout my Sass projects like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::text&amp;#x000A;stylesheets/&amp;#x000A;|&amp;#x000A;|-- modules/              # Common modules&amp;#x000A;|   |-- _all.scss         # Include to get all modules&amp;#x000A;|   |-- _utility.scss     # Module name&amp;#x000A;|   |-- _colors.scss      # Etc...&amp;#x000A;|   ...&amp;#x000A;|&amp;#x000A;|-- partials/             # Partials&amp;#x000A;|   |-- _base.sass        # imports for all mixins + global project variables&amp;#x000A;|   |-- _buttons.scss     # buttons&amp;#x000A;|   |-- _figures.scss     # figures&amp;#x000A;|   |-- _grids.scss       # grids&amp;#x000A;|   |-- _typography.scss  # typography&amp;#x000A;|   |-- _reset.scss       # reset&amp;#x000A;|   ...&amp;#x000A;|&amp;#x000A;|-- vendor/               # CSS or Sass from other projects&amp;#x000A;|   |-- _colorpicker.scss&amp;#x000A;|   |-- _jquery.ui.core.scss&amp;#x000A;|   ...&amp;#x000A;|&amp;#x000A;`-- main.scss            # primary Sass file&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id='primary_stylesheet'&gt;Primary stylesheet&lt;/h2&gt;

&lt;p&gt;This allows me to keep my primary Sass file extremely clean:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::scss&amp;#x000A;// Modules and Variables&amp;#x000A;@import &amp;quot;partials/base&amp;quot;;&amp;#x000A;&amp;#x000A;// Partials&amp;#x000A;@import &amp;quot;partials/reset&amp;quot;;&amp;#x000A;@import &amp;quot;partials/typography&amp;quot;;&amp;#x000A;@import &amp;quot;partials/buttons&amp;quot;;&amp;#x000A;@import &amp;quot;partials/figures&amp;quot;;&amp;#x000A;@import &amp;quot;partials/grids&amp;quot;;&amp;#x000A;// ...&amp;#x000A;&amp;#x000A;// Third-party&amp;#x000A;@import &amp;quot;vendor/colorpicker&amp;quot;;&amp;#x000A;@import &amp;quot;vendor/jquery.ui.core&amp;quot;;&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id='modules_partials_and_vendor'&gt;Modules, partials, and vendor&lt;/h2&gt;

&lt;p&gt;As you can see this divides my project into three basic types of files. Modules, partials, and vendored stylesheets.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The &lt;strong&gt;modules&lt;/strong&gt; directory is reserved for Sass code that doesn&amp;#8217;t cause Sass to actually output CSS. Things like mixin declarations, functions, and variables.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;The &lt;strong&gt;partials&lt;/strong&gt; directory is where the meat of my CSS is constructed. A lot of folks like to break their stylesheets into header, content, sidebar, and footer components (and a few others). As I&amp;#8217;m more of a &lt;a href='http://smacss.com/'&gt;SMACSS&lt;/a&gt; guy myself, I like to break things down into much finer categories (typography, buttons, textboxes, selectboxes, etc&amp;#8230;).&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;The &lt;strong&gt;vendor&lt;/strong&gt; directory is for third-party CSS. This is handy when using prepackaged components developed by other people (or for your own components that are maintained in another project). jQuery UI and a color picker are examples of CSS that you might want to place in the vendor directory. As a general rule I make it a point not to modify files in my vendor directory. If I need to make modifications I add those after the vendored files are included in my primary stylesheet. This should make it easy for me to update my third-party stylesheets to more current versions in the future.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='using_a_base_partial'&gt;Using a base partial&lt;/h2&gt;

&lt;p&gt;In my partials directory you will also notice that I have a base partial. The purpose of this partial is to load up my Sass environment so that it&amp;#8217;s easy to construct a stylesheet.&lt;/p&gt;

&lt;p&gt;It might look something like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::scss&amp;#x000A;// Use Compass (&amp;#39;cause it rocks!)&amp;#x000A;@import &amp;quot;compass&amp;quot;;&amp;#x000A;&amp;#x000A;// Font weights&amp;#x000A;$light: 100;&amp;#x000A;$regular: 400;&amp;#x000A;$bold: 600;&amp;#x000A;&amp;#x000A;// Base Font&amp;#x000A;$base-font-family: sans-serif;&amp;#x000A;$base-font-weight: $regular;&amp;#x000A;$base-font-size: 13px;&amp;#x000A;$base-line-height: 1.4;&amp;#x000A;&amp;#x000A;// Fixed Font&amp;#x000A;$fixed-font-family: monospace;&amp;#x000A;$fixed-font-size: 85%;&amp;#x000A;$fixed-line-height: $base-line-height;&amp;#x000A;&amp;#x000A;// Headings&amp;#x000A;$header-font-weight: $bold;&amp;#x000A;&amp;#x000A;@import &amp;quot;modules/all&amp;quot;;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The base stylesheet sets a couple of global variables and loads up all of my Sass modules. Again modules are not allowed to contain anything that would cause CSS output when importing. Tying all of my varibles and modules up into a base partial gives me access to my entire Sass environment whenever I&amp;#8217;m setting up a new stylesheet with a single import statement. This allows me to build multiple stylesheets by importing different partials. Multiple stylesheets are handy once a project grows to a certain size.&lt;/p&gt;

&lt;h2 id='one_step_further'&gt;One step further&lt;/h2&gt;

&lt;p&gt;At &lt;a href='http://uservoice.com'&gt;UserVoice&lt;/a&gt; we take this pattern one step further. Since we have multiple sub-projects all bundled together in a single Rails app, we bundle each sub-project into a separate top-level directory. Our stylesheet directory looks more like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::text&amp;#x000A;stylesheets/&amp;#x000A;|&amp;#x000A;|-- admin/           # Admin sub-project&amp;#x000A;|   |-- modules/&amp;#x000A;|   |-- partials/&amp;#x000A;|   `-- _base.scss&amp;#x000A;|&amp;#x000A;|-- account/         # Account sub-project&amp;#x000A;|   |-- modules/&amp;#x000A;|   |-- partials/&amp;#x000A;|   `-- _base.scss&amp;#x000A;|&amp;#x000A;|-- site/            # Site sub-project&amp;#x000A;|   |-- modules/&amp;#x000A;|   |-- partials/&amp;#x000A;|   `-- _base.scss&amp;#x000A;|&amp;#x000A;|-- vendor/          # CSS or Sass from other projects&amp;#x000A;|   |-- _colorpicker-1.1.scss&amp;#x000A;|   |-- _jquery.ui.core-1.9.1.scss&amp;#x000A;|   ...&amp;#x000A;|&amp;#x000A;|-- admin.scss       # Primary stylesheets for each project&amp;#x000A;|-- account.scss&amp;#x000A;`-- site.scss&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As you can see each sub-project has it&amp;#8217;s own primary stylesheet, modules, partials, and base. Vendored stylesheets are typically versioned and have their own top-level directory. This is a handy pattern to use on very large Sass projects.&lt;/p&gt;

&lt;h2 id='further_exploration'&gt;Further exploration&lt;/h2&gt;

&lt;p&gt;Now that I&amp;#8217;ve laid out my own method for this, you may want to explore how other people have structured their Sass projects. There&amp;#8217;s actually a lot of variation in what you can do here. And some methods may work better on different projects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='https://github.com/chriseppstein/compass/tree/stable/frameworks'&gt;Compass&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='https://github.com/lesjames/Breakpoint/tree/master/static/sass'&gt;Breakpoint&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='https://github.com/imathis/octopress/tree/master/.themes/classic/sass'&gt;Octopress&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='https://github.com/jlong/sass-twitter-bootstrap/tree/master/lib'&gt;Sass Twitter Bootstrap&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also check out Dale Sande&amp;#8217;s excellent article, &lt;a href='http://gist.io/4436524'&gt;&lt;em&gt;Clean out your Sass junk drawer&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;</content>
    <published>2013-04-03T00:00:00+00:00</published>
    <updated>2013-04-03T00:00:00+00:00</updated>
    <category term="beginner" />
    <category term="guides" />
    <category term="john-w-long" />
  </entry>
  <entry>
    <title>Responsive Web Design in Sass: Using Media Queries in Sass 3.2</title>
    <link href="http://thesassway.com/intermediate/responsive-web-design-in-sass-using-media-queries-in-sass-32" rel="alternate" type="text/html" />
    <id>tag:thesassway.com,2012-04-09:/intermediate/responsive-web-design-in-sass-using-media-queries-in-sass-32</id>
    <content type="html">&lt;p&gt;In &lt;a href='http://thesassway.com/intermediate/responsive-web-design-part-2'&gt;Responsive Web Design in Sass Part 2&lt;/a&gt; I wrote about using media queries in Sass 3.1. At the time, I was mostly limited to the (still very cool) &lt;a href='http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#media'&gt;@media bubbling&lt;/a&gt; feature. I also pointed out some of the shortcomings.&lt;/p&gt;

&lt;p&gt;At the end of the post I previewed how you can use &lt;a href='https://gist.github.com/1215856'&gt;@content blocks&lt;/a&gt;, one of the emerging features of Sass 3.2, to write a mixin that can really help to simplify using media queries in Sass. With Sass 3.2 nearly upon us, I am happy to report that media queries have become the first-class citizens they deserve to be. Let&amp;#8217;s see what&amp;#8217;s new.&lt;/p&gt;

&lt;h2 id='variables_in_queries'&gt;Variables in queries&lt;/h2&gt;

&lt;p&gt;If you tried to use a variable in the media query test in Sass 3.1 it would fail by simply spitting out the actual text of the variable name. This is fixed in Sass 3.2, and works pretty much as I always expected it would.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::scss&amp;#x000A;$break-small: 320px;&amp;#x000A;$break-large: 1200px;&amp;#x000A;&amp;#x000A;.profile-pic {&amp;#x000A;  float: left;&amp;#x000A;  width: 250px;&amp;#x000A;  @media screen and (max-width: $break-small) {&amp;#x000A;    width: 100px;&amp;#x000A;    float: none;&amp;#x000A;  }&amp;#x000A;  @media screen and (min-width: $break-large) {&amp;#x000A;    float: right;&amp;#x000A;  }&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Compiles to:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::css&amp;#x000A;profile-pic {&amp;#x000A;  float: left;&amp;#x000A;  width: 250px;&amp;#x000A;}&amp;#x000A;@media screen and (max-width: 320px) {&amp;#x000A;  .profile-pic {&amp;#x000A;    width: 100px;&amp;#x000A;    float: none;&amp;#x000A;  }&amp;#x000A;}&amp;#x000A;@media screen and (min-width: 1200px) {&amp;#x000A;  .profile-pic {&amp;#x000A;    float: right;&amp;#x000A;  }&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id='variables_as_full_query'&gt;Variables as full query&lt;/h2&gt;

&lt;p&gt;You&amp;#8217;re not limited to using variables in the numerical part of a @media test. Go ahead and set the whole test as a variable. (Note the need for the interpolation braces &lt;code&gt;#{}&lt;/code&gt;)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::scss&amp;#x000A;$information-phone: &amp;quot;only screen and (max-width : 320px)&amp;quot;;&amp;#x000A;&amp;#x000A;@media #{$information-phone} {&amp;#x000A;  background: red;&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Compiles to:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::css&amp;#x000A;@media only screen and (max-width : 320px) {&amp;#x000A;  background: red;&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id='variables_on_either_side_of_the_colon_in_a_query'&gt;Variables on either side of the colon in a query&lt;/h2&gt;

&lt;p&gt;You can also get really abstract and set a variable for items on either side of the colon in a test. I can see this being very usefull in building flexible responsive frameworks.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::scss&amp;#x000A;$width-name: max-device-width;&amp;#x000A;$target-width: 320px;&amp;#x000A;&amp;#x000A;@media screen and ($width-name : $target-width) {&amp;#x000A;  background: red;&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Compiles to&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::css&amp;#x000A;@media screen and (max-device-width: 320px) {&amp;#x000A;  background: red;&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can also do math on a variable in a query, like so:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::sass&amp;#x000A;@media screen and ($width-name : $target-width + 1) {&amp;#x000A;  background: red;&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Compiles to&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::css&amp;#x000A;@media screen and (max-device-width: 321px) {&amp;#x000A;  background: red;&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id='variables_in_queries_using_content'&gt;Variables in queries, using @content&lt;/h2&gt;

&lt;p&gt;In &lt;a href='http://thesassway.com/intermediate/responsive-web-design-part-2'&gt;Responsive Web Design in Sass Part 2&lt;/a&gt;, I illustrated how to write some nicely abstracted media query systems using &lt;code&gt;@content&lt;/code&gt; blocks in mixins. Now you can take that a step further by using variables in the actual queries. I think this will be very helpful in refining a set of breakpoints.&lt;/p&gt;

&lt;p&gt;On my next project, I think I&amp;#8217;ll start with some of the usual device-related breakpoints (320, 480, 720) as &amp;#8220;placeholder&amp;#8221; breakpoints. Then as I progress in building my design I&amp;#8217;ll alter those to whatever values suit my design.&lt;/p&gt;

&lt;p&gt;SCSS&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::scss&amp;#x000A;$break-small: 320px;&amp;#x000A;$break-large: 1024px;&amp;#x000A;&amp;#x000A;@mixin respond-to($media) {&amp;#x000A;  @if $media == handhelds {&amp;#x000A;    @media only screen and (max-width: $break-small) { @content; }&amp;#x000A;  }&amp;#x000A;  @else if $media == medium-screens {&amp;#x000A;    @media only screen and (min-width: $break-small + 1) and (max-width: $break-large - 1) { @content; }&amp;#x000A;  }&amp;#x000A;  @else if $media == wide-screens {&amp;#x000A;    @media only screen and (min-width: $break-large) { @content; }&amp;#x000A;  }&amp;#x000A;}&amp;#x000A;&amp;#x000A;.profile-pic {&amp;#x000A;  float: left;&amp;#x000A;  width: 250px;&amp;#x000A;  @include respond-to(handhelds) { width: 100% ;}&amp;#x000A;  @include respond-to(medium-screens) { width: 125px; }&amp;#x000A;  @include respond-to(wide-screens) { float: none; }&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;CSS&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::css&amp;#x000A;.profile-pic {&amp;#x000A;  float: left;&amp;#x000A;  width: 250px;&amp;#x000A;}&amp;#x000A;@media only screen and (max-width: 320px) {&amp;#x000A;  .profile-pic {&amp;#x000A;    width: 100%;&amp;#x000A;  }&amp;#x000A;}&amp;#x000A;@media only screen and (min-width: 321px) and (max-width: 1023px) {&amp;#x000A;  .profile-pic {&amp;#x000A;    width: 125px;&amp;#x000A;  }&amp;#x000A;}&amp;#x000A;@media only screen and (min-width: 1024px) {&amp;#x000A;  .profile-pic {&amp;#x000A;    float: none;&amp;#x000A;  }&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id='nothing_is_perfect'&gt;Nothing is Perfect&lt;/h2&gt;

&lt;h3 id='extend_within_media'&gt;@extend within @media&lt;/h3&gt;

&lt;p&gt;There are features and optimisations I&amp;#8217;d like to see regarding &lt;code&gt;@media&lt;/code&gt; handling in Sass. For example &lt;code&gt;@extend&lt;/code&gt; doesn&amp;#8217;t behave like I&amp;#8217;d expect when I use it in a media query.&lt;/p&gt;

&lt;p&gt;When I write the Following in SCSS:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::scss&amp;#x000A;.red {&amp;#x000A;  color: red;&amp;#x000A;  }&amp;#x000A;&amp;#x000A;.blue {&amp;#x000A;  color: blue;&amp;#x000A;}&amp;#x000A;&amp;#x000A;@media only screen and (max-width : 300px){&amp;#x000A;  .blue {&amp;#x000A;    @extend .red;&amp;#x000A;    margin: 10px;&amp;#x000A;  }&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I intended for the generated css to look something like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::css&amp;#x000A;.red {&amp;#x000A;  color: red;&amp;#x000A;}&amp;#x000A;@media only screen and (max-width: 300px) {&amp;#x000A;  .blue {&amp;#x000A;    color: red;&amp;#x000A;  }&amp;#x000A;}&amp;#x000A;&amp;#x000A;.blue {&amp;#x000A;  color: blue;&amp;#x000A;}&amp;#x000A;&amp;#x000A;@media only screen and (max-width: 300px) {&amp;#x000A;  .blue {&amp;#x000A;    margin: 10px;&amp;#x000A;  }&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But what I really got wasn&amp;#8217;t nearly as useful.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::css&amp;#x000A;.red, .blue {&amp;#x000A;  color: red;&amp;#x000A;}&amp;#x000A;&amp;#x000A;.blue {&amp;#x000A;  color: blue;&amp;#x000A;}&amp;#x000A;&amp;#x000A;@media only screen and (max-width: 300px) {&amp;#x000A;  .blue {&amp;#x000A;    margin: 10px;&amp;#x000A;  }&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This is a hairy issue, and different use cases suggest different results. Eventually this may just be &lt;a href='https://github.com/nex3/sass/issues/154'&gt;disallowed&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id='combining_media_queries_on_compile'&gt;Combining @media Queries on Compile&lt;/h3&gt;

&lt;p&gt;One feature I hear a lot of people bring up with &lt;code&gt;@media&lt;/code&gt; bubbling is that you often end up with the same query in many places in your compiled CSS. The resulting CSS would be much smaller and more closely resemble &amp;#8220;handcrafted&amp;#8221; CSS if all the rules that match a particular query be combined when the CSS is compiled.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::scss&amp;#x000A;.profile-pic {&amp;#x000A;  @media screen and (max-width: 320px) {&amp;#x000A;    width: 100px;&amp;#x000A;    float: none;&amp;#x000A;  }&amp;#x000A;}&amp;#x000A;&amp;#x000A;.biography {&amp;#x000A;  @media screen and (max-width: 320px) {&amp;#x000A;    font-size: 1.5em;&amp;#x000A;  }&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It would be nice (and smaller) if that became:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::css&amp;#x000A;@media screen and (max-width: 320px) {&amp;#x000A;  .profile-pic {&amp;#x000A;    width: 100px;&amp;#x000A;    float: none;&amp;#x000A;  }&amp;#x000A;  .biography {&amp;#x000A;    font-size: 1.5em;&amp;#x000A;  }&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But instead we get:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::css&amp;#x000A;@media screen and (max-width: 320px) {&amp;#x000A;  .profile-pic {&amp;#x000A;    width: 100px;&amp;#x000A;    float: none;&amp;#x000A;  }&amp;#x000A;}&amp;#x000A;&amp;#x000A;@media screen and (max-width: 320px) {&amp;#x000A;  .biography {&amp;#x000A;    font-size: 1.5em;&amp;#x000A;  }&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Nothing&amp;#8217;s broken here, but it&amp;#8217;s certainly not optimal. I think this would be a &lt;a href='https://github.com/nex3/sass/issues/116'&gt;great issue&lt;/a&gt; to tackle, and it looks like there are some other smart optimisations they&amp;#8217;re considering.&lt;/p&gt;

&lt;h2 id='so_go_get_it'&gt;So go get it!&lt;/h2&gt;

&lt;p&gt;As before, you don&amp;#8217;t have to work hard to get the new good stuff. Just run the following in your command line and you&amp;#8217;re all set.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gem install sass --pre&lt;/code&gt;&lt;/p&gt;</content>
    <published>2012-04-09T06:00:00-05:00</published>
    <updated>2012-04-09T06:00:00-05:00</updated>
    <category term="guides" />
    <category term="intermediate" />
    <category term="mason-wendell" />
  </entry>
  <entry>
    <title>A Standard Module Definition for Sass</title>
    <link href="http://thesassway.com/intermediate/a-standard-module-definition-for-sass" rel="alternate" type="text/html" />
    <id>tag:thesassway.com,2012-03-26:/intermediate/a-standard-module-definition-for-sass</id>
    <content type="html">&lt;p&gt;Since becoming a fan of Sass, one thing that has bothered me is that not much has been written about best practices for structuring Sass projects. This is one of a series of articles we will be writing to talk about some of the things that folks are doing to make their projects better.&lt;/p&gt;

&lt;p&gt;In this article, I&amp;#8217;d like to kickstart the discussion on developing a &lt;em&gt;Standard Module Definition&lt;/em&gt; for Sass. I&amp;#8217;ll start by sharing a couple of principles that I&amp;#8217;ve found helpful for structuring Sass projects. (The principles here apply mostly to writing Sass for non-library code. We&amp;#8217;ll talk more about some ideas for structuring library modules in a future article.)&lt;/p&gt;

&lt;h2 id='1_a_module_is_a_unit_of_code_contained_in_a_partial'&gt;1. A module is a unit of code contained in a partial&lt;/h2&gt;

&lt;p&gt;I like to define modules in Sass partials. Since Sass doesn&amp;#8217;t currently have a way to namespace code, the easiest way to group code by function is to do so in a partial. One module per file. Example module names in typical projects might include: buttons, forms, lists, and typography.&lt;/p&gt;

&lt;h2 id='2_importing_a_module_should_never_output_code'&gt;2. Importing a module should never output code&lt;/h2&gt;

&lt;p&gt;I&amp;#8217;m a strong believer in keeping your modules free of anything that would cause immediate CSS output. The idea is that you should be able to import any number of modules into your code-base and then make selective calls to control the output. This pretty much limits modules to mixins, functions, and variable definitions. (Sass 3.2 also introduces &lt;em&gt;placeholder selectors&lt;/em&gt; which could also be used in a module definition.)&lt;/p&gt;

&lt;h2 id='3_each_module_should_have_a_primary_mixin'&gt;3. Each module should have a primary mixin&lt;/h2&gt;

&lt;p&gt;If appropriate, a primary mixin should be included in each module that outputs the standard usage of the module. This one is a little tricker to explain with words, so let me show you in code.&lt;/p&gt;

&lt;p&gt;Here is an example &lt;code&gt;_buttons.scss&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::scss&amp;#x000A;// Primary mixin&amp;#x000A;@mixin buttons {&amp;#x000A;  a.button, button {&amp;#x000A;    @include button(black, silver);&amp;#x000A;    &amp;amp;.blue  { @include button(white, blue); }&amp;#x000A;    &amp;amp;.red   { @include button(white, red); }&amp;#x000A;    &amp;amp;.green { @include button(white, green); }&amp;#x000A;  }&amp;#x000A;}&amp;#x000A;&amp;#x000A;// Button mixin&amp;#x000A;@mixin button($text-color, $bg-color) {&amp;#x000A;  font: 12px bold sans-serif;&amp;#x000A;  padding: 3px 8px;&amp;#x000A;  @include color-button($text-color, $bg-color));&amp;#x000A;  &amp;amp;:hover, &amp;amp;:focus { @include color-button($text-color, lighten($bg-color, 10%)); }&amp;#x000A;  &amp;amp;:active { background: darken($bg-color, 5%); }&amp;#x000A;}&amp;#x000A;&amp;#x000A;// Color button mixin&amp;#x000A;@mixin color-button($text-color, $bg-color) {&amp;#x000A;  color: $text-color;&amp;#x000A;  border: 1px solid mix(black, $bg-color);&amp;#x000A;  @include background-image(&amp;#x000A;    linear-gradient(&amp;#x000A;      lighten($bg-color, 5%),&amp;#x000A;      darken($bg-color, 5%)&amp;#x000A;    )&amp;#x000A;  );&amp;#x000A;}&amp;#x000A;&amp;#x000A;...&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The idea here is that the buttons module includes all kinds of mixins for creating and styling buttons, but the primary mixin demonstrates and applies the default usage of the appropriate mixins. This makes it super simple to use the default behavior for a module in a stylesheet.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s an example of how I often combine modules in my main stylesheet:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::scss&amp;#x000A;.content {&amp;#x000A;  @include typography;&amp;#x000A;  @include buttons;&amp;#x000A;  @include lists;&amp;#x000A;  @include forms;&amp;#x000A;  ...&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id='4_the_name_of_the_primary_mixin_should_inherit_the_name_of_the_module'&gt;4. The name of the primary mixin should inherit the name of the module&lt;/h2&gt;

&lt;p&gt;I&amp;#8217;d recommend that you try to pluralize your module names, where appropriate, and the name of your main mixin for that module should be the same as the name of the module itself. This simple naming convention will make it easy to import and use your modules without thinking hard about the names.&lt;/p&gt;

&lt;h2 id='5_variable_definitions_should_always_be_defaulted'&gt;5. Variable definitions should always be defaulted&lt;/h2&gt;

&lt;p&gt;If a module defines top-level variables, they should always be defined with the &lt;code&gt;!default&lt;/code&gt; directive. This will make it much easier to override those variables in a theme stylesheet or when reusing the module for other purposes.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s an example of using the &lt;code&gt;!default&lt;/code&gt; directive to declare defaults for variables within a module:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::scss&amp;#x000A;$base-font-family: Helvetica, Arial, sans-serif !default;&amp;#x000A;$fixed-font-family: monospace !default;&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id='6_almost_all_project_css_should_be_written_in_modules'&gt;6. Almost all project CSS should be written in modules&lt;/h2&gt;

&lt;p&gt;I like to code almost all of my CSS in modules using this pattern. This makes it much easier to reuse styles across stylesheets for a given project or even to share code between projects. It also helps me think about my code in a modular way from the very beginning &amp;#8211; a discipline that I find quite helpful.&lt;/p&gt;

&lt;p&gt;For me, modules have become the basic units or building blocks of my Sass projects. What practices do you find helpful for structuring your own projects?&lt;/p&gt;</content>
    <published>2012-03-26T16:15:00-05:00</published>
    <updated>2012-03-26T16:15:00-05:00</updated>
    <category term="guides" />
    <category term="intermediate" />
    <category term="john-w-long" />
  </entry>
  <entry>
    <title>Sass doesn't create bad code. Bad coders do.</title>
    <link href="http://thesassway.com/articles/sass-doesnt-create-bad-code-bad-coders-do" rel="alternate" type="text/html" />
    <id>tag:thesassway.com,2012-02-02:/articles/sass-doesnt-create-bad-code-bad-coders-do</id>
    <content type="html">&lt;p&gt;Those who don&amp;#8217;t see any use for pre-processors such as Sass often use the &amp;#8220;bad code&amp;#8221; argumentation. It creates too specific selectors due to nesting, huge sprites and they hate the way Sass enforces an architectural approach that doesn&amp;#8217;t work. And it&amp;#8217;s all true. If you&amp;#8217;re a poor developer. You know, one who would handcraft too specific selectors, 15MB sprites and doesn&amp;#8217;t know how to cleanly structure a project.&lt;/p&gt;

&lt;h2 id='debunking_the_arguments_against_sass'&gt;Debunking the arguments against Sass&lt;/h2&gt;

&lt;p&gt;With this article I&amp;#8217;ll try to debunk the arguments against using Sass that create fear, uncertainty and doubt. I believe these arguments to be in error and used by those who don&amp;#8217;t have actual experience with pre-processors or have worked with people who didn&amp;#8217;t &amp;#8220;get it&amp;#8221;. I&amp;#8217;m sure I can convert any CSS out there to Sass, using substantially fewer characters, while maintaining the exact same output. Whatever Sass compiles to is up to you. Now, bring it on!&lt;/p&gt;

&lt;h2 id='nesting_leads_to_overly_specific_selectors'&gt;&amp;#8220;Nesting leads to overly specific selectors&amp;#8221;&lt;/h2&gt;

&lt;p&gt;Too much nesting sure does. There&amp;#8217;s a pretty nifty solution for this: don&amp;#8217;t do it. Mario has written an excellent article about &lt;a href='http://thesassway.com/beginner/the-inception-rule'&gt;the inception rule&lt;/a&gt; here on The Sass Way.&lt;/p&gt;

&lt;p&gt;I understand it&amp;#8217;s easy to fall prey to this; &lt;a href='http://37signals.com/svn/posts/3003-css-taking-control-of-the-cascade'&gt;even 37signals does it&lt;/a&gt;. The basic rule is: don&amp;#8217;t try to mimic your HTML structure in your Sass. It may seem handy at first, but in the end it will lead to completely non-reusable code due to the extreme specificity of selectors. You&amp;#8217;ll end up copy/pasting chunks of Sass and cause code duplication. Keep your selectors shallow.&lt;/p&gt;

&lt;h2 id='mixins_will_bloat_your_css_by_repeating_code'&gt;&amp;#8220;Mixins will bloat your CSS by repeating code&amp;#8221;&lt;/h2&gt;

&lt;p&gt;They may. When a mixin holds five lines of code, including it in your Sass ten times will lead to 50 lines of CSS. In most cases you don&amp;#8217;t want that. My rule of thumb is: mixins without arguments smell. When the return value of your mixin is dependent on arguments you pass to it, it should generate different output with every use. For a mixin that returns the width based on a number of columns when using a grid based layout for instance, that makes complete sense.&lt;/p&gt;

&lt;p&gt;For a lot of other uses, the &lt;code&gt;@extend&lt;/code&gt; directive may be a better choice (as long as you read the next paragraph).&lt;/p&gt;

&lt;h2 id='the_extend_directive_creates_a_lot_of_ugly_selectors'&gt;&amp;#8220;The extend directive creates &lt;em&gt;a lot&lt;/em&gt; of ugly selectors&amp;#8221;&lt;/h2&gt;

&lt;p&gt;Ask yourself if your compiled CSS is meant to be human readable or machine readable. If you work in Sass, but know the resulting CSS will be hand edited, I would avoid extending selectors. When using &lt;code&gt;@extend&lt;/code&gt; two times on a single selector, there will be code related to it at three places in the CSS (assuming you aren&amp;#8217;t nesting extends).&lt;/p&gt;

&lt;p&gt;For a browser however, the way the code is formatted doesn&amp;#8217;t really matter, which is why minifying your code is a best practice. Pretty code is less important than performant code, and extending your selectors can definitely lead to DRY&amp;#8217;er code than using mixins. On the other hand, don&amp;#8217;t overdo it. If you find yourself extending your &lt;code&gt;.clearfix&lt;/code&gt; class twenty times, you may consider adding it to your HTML (or learn how floats work). Use common sense.&lt;/p&gt;

&lt;h2 id='you_cant_use_sass_in_an_oocss_or_any_other_architectural_approach'&gt;&amp;#8220;You can&amp;#8217;t use Sass in an OOCSS (or any other architectural) approach&amp;#8221;&lt;/h2&gt;

&lt;p&gt;Sure you can. If you want to use class names on every element in your HTML and define (extreme) shallow selectors in your CSS, Sass has got your back. If you want to take a nested approach, where you only set a class name on a wrapper element and use descendant selectors in your CSS, Sass is a good fit. You could even just take your handcrafted CSS, rename it to SCSS and only use those features in Sass and Compass that brighten up your day. Sass doesn&amp;#8217;t have anything to do with your architectural approach. Tell it what to do, and it will do it.&lt;/p&gt;

&lt;h2 id='know_your_compiler'&gt;Know your compiler&lt;/h2&gt;

&lt;p&gt;You don&amp;#8217;t need to know the internals of Sass to know what will be done to your code. Just open the processed CSS once in a while and see what it looks like. It isn&amp;#8217;t rocket science to learn to predict what your Sass code will be compiled too. It&amp;#8217;s a good thing to think &amp;#8220;how would I do this in plain ol&amp;#8217; CSS&amp;#8221; when writing Sass. At least you&amp;#8217;ll know if a certain use of &lt;code&gt;@extend&lt;/code&gt; adds a gazillion selectors to your CSS and make an informed decision as to use it or not.&lt;/p&gt;

&lt;h2 id='sass_is_just_a_tool'&gt;Sass is just a tool&lt;/h2&gt;

&lt;p&gt;Just as you can&amp;#8217;t expect everyone who holds a hammer to be a master carpenter, Sass doesn&amp;#8217;t automagically turn you into a great front-end developer. In the end, Sass is &amp;#8220;just&amp;#8221; a powerful tool. And when taking responsibility in this great power, it will help you write and maintain your stylesheets the easy way, whatever approach you to take. Know what you&amp;#8217;re doing and you&amp;#8217;ll be fine.&lt;/p&gt;</content>
    <published>2012-02-02T10:00:00-06:00</published>
    <updated>2012-02-02T10:00:00-06:00</updated>
    <category term="articles" />
    <category term="roy-tomeij" />
  </entry>
  <entry>
    <title>Zurb Foundation, for Sass and Compass</title>
    <link href="http://thesassway.com/projects/zurb-foundation" rel="alternate" type="text/html" />
    <id>tag:thesassway.com,2011-12-22:/projects/zurb-foundation</id>
    <content type="html">&lt;p&gt;What do you get when combine the power of Sass with Zurb? You get Zurb Foundation for Sass and Compass.&lt;/p&gt;
&lt;a href='http://foundation.zurb.com/'&gt;&lt;img class='full' src='/attachments/zurb-foundation.png' /&gt;&lt;/a&gt;
&lt;h2 id='foundation_is_awesome'&gt;Foundation is awesome.&lt;/h2&gt;

&lt;p&gt;I come out of the gate saying, &amp;#8220;Foundation is awesome.&amp;#8221; It&amp;#8217;s the perfect flexible grid from desktop to mobile.&lt;/p&gt;

&lt;p&gt;Foundation includes forms, buttons, and a UI library. Plus other &lt;a href='http://www.zurb.com/playground'&gt;ZURB Playground&lt;/a&gt; favorites like &lt;a href='http://www.zurb.com/playground/orbit-jquery-image-slider'&gt;Orbit&lt;/a&gt; and &lt;a href='http://www.zurb.com/playground/reveal-modal-plugin'&gt;Reveal&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;With &lt;a href='http://foundation.zurb.com/case-foundation.php'&gt;case studies&lt;/a&gt; like &lt;a href='http://www.zurb.com/jobs'&gt;ZURB Jobs&lt;/a&gt;, &lt;a href='http://foundation.zurb.com/case-swizzle.php'&gt;Swizzle&lt;/a&gt; and &lt;a href='http://foundation.zurb.com/case-foundation.php'&gt;the Foundation site itself&lt;/a&gt;, how can we deny ZURB of hitting this one out of the park?&lt;/p&gt;
&lt;a href='http://www.getswizzle.com/'&gt;&lt;img class='full' src='http://foundation.zurb.com/images/case-swizzle.jpg' /&gt;&lt;/a&gt;
&lt;h2 id='foundations_features'&gt;Foundation&amp;#8217;s Features&lt;/h2&gt;

&lt;p&gt;ZURB Foundation features a set of global styles that include Eric Meyer&amp;#8217;s reset, tested styles for typography, links, lists, tables and more.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='http://foundation.zurb.com/grid.php'&gt;The Grid&lt;/a&gt;, built for &lt;a href='http://foundation.zurb.com/prototyping.php'&gt;rapid prototyping&lt;/a&gt; and &lt;a href='http://foundation.zurb.com/mobile.php'&gt;mobility&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;Various &lt;a href='http://foundation.zurb.com/docs/layout.php'&gt;layout&lt;/a&gt; options&lt;/li&gt;

&lt;li&gt;&lt;a href='http://foundation.zurb.com/docs/ui.php'&gt;UI Elements&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://foundation.zurb.com/docs/buttons.php'&gt;Buttons&lt;/a&gt; and &lt;a href='http://foundation.zurb.com/docs/forms.php'&gt;forms&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;Plus &lt;a href='http://www.zurb.com/playground'&gt;playground&lt;/a&gt; favorites &lt;a href='http://www.zurb.com/playground/orbit-jquery-image-slider'&gt;Orbit&lt;/a&gt; and &lt;a href='http://www.zurb.com/playground/reveal-modal-plugin'&gt;Reveal&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And ZURB didn&amp;#8217;t stop there, they did an awesome job showing off &lt;a href='http://foundation.zurb.com/docs/index.php'&gt;the documentation&lt;/a&gt; too. You can learn about all the features of Foundation, as well as how to use it on mobile and desktop displays.&lt;/p&gt;

&lt;h2 id='installation'&gt;Installation&lt;/h2&gt;

&lt;p&gt;From your Terminal &amp;#8230;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash&amp;#x000A;(sudo) gem install ZURB-foundation&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you use &lt;a href='http://gembundler.com/'&gt;Bundler&lt;/a&gt;, simply add &lt;code&gt;ZURB-foundation&lt;/code&gt; to your &lt;code&gt;Gemfile&lt;/code&gt; and &lt;code&gt;bundle install&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash&amp;#x000A;gem &amp;#39;ZURB-foundation&amp;#39;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Form here, you have a few options on getting started with ZURB Foundation. You can start a Compass-based project with ZURB Foundation or you can install ZURB Foundation into an existing Compass-based project.&lt;/p&gt;

&lt;h3 id='start_a_compassbased_project_with_zurb_foundation'&gt;Start a Compass-based project with ZURB Foundation&lt;/h3&gt;

&lt;p&gt;You can start a brand new project using Compass and ZURB Foundation with the following &lt;code&gt;compass&lt;/code&gt; command.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash&amp;#x000A;compass create &amp;lt;project-name&amp;gt; -r ZURB-foundation --using ZURB-foundation --force&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you&amp;#8217;d like to require ZURB Foundation to install using a particular Sass syntax, use the Compass &lt;code&gt;--syntax&lt;/code&gt; flag. Here&amp;#8217;s an example.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash&amp;#x000A;compass create &amp;lt;my_project&amp;gt; -r ZURB-foundation --using ZURB-foundation --syntax sass --force&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id='install_zurb_foundation_into_an_existing_compassbased_project'&gt;Install ZURB Foundation into an existing Compass-based project&lt;/h3&gt;

&lt;p&gt;You can install ZURB Foundation into an existing project with Compass in place already.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash&amp;#x000A;compass install ZURB-foundation/project&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Running this will unfurl a number of files from the ZURB Foundation gem using the Compass framework.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash&amp;#x000A;-&amp;gt; % compass install ZURB-foundation/project&amp;#x000A;directory images/misc/ &amp;#x000A;directory images/orbit/ &amp;#x000A;directory javascripts/ &amp;#x000A;directory sass/ &amp;#x000A;directory stylesheets/ &amp;#x000A;   create sass/app.scss &amp;#x000A;   create sass/ie.scss &amp;#x000A;   create javascripts/app.js &amp;#x000A;   create javascripts/forms.jquery.js &amp;#x000A;   create javascripts/jquery.customforms.js &amp;#x000A;   create javascripts/jquery.min.js &amp;#x000A;   create javascripts/jquery.reveal.js &amp;#x000A;   create javascripts/jquery.orbit-1.3.0.js &amp;#x000A;   create javascripts/jquery.placeholder.min.js &amp;#x000A;   create index.html &amp;#x000A;   create humans.txt &amp;#x000A;   create robots.txt &amp;#x000A;   create MIT-LICENSE.txt &amp;#x000A;   create images/misc/button-gloss.png &amp;#x000A;   create images/misc/button-overlay.png &amp;#x000A;   create images/misc/custom-form-sprites.png &amp;#x000A;   create images/misc/input-bg.png &amp;#x000A;   create images/misc/modal-gloss.png &amp;#x000A;   create images/misc/table-sorter.png &amp;#x000A;   create images/orbit/bullets.jpg &amp;#x000A;   create images/orbit/left-arrow.png &amp;#x000A;   create images/orbit/loading.gif &amp;#x000A;   create images/orbit/mask-black.png &amp;#x000A;   create images/orbit/pause-black.png &amp;#x000A;   create images/orbit/right-arrow.png &amp;#x000A;   create images/orbit/rotator-black.png &amp;#x000A;   create images/orbit/timer-black.png &amp;#x000A;   create stylesheets/app.css &amp;#x000A;   create stylesheets/ie.css &lt;/code&gt;&lt;/pre&gt;

&lt;h2 id='awesome_examples_to_check_out'&gt;Awesome examples to check out&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='http://foundation.zurb.com/prototype-example2.php'&gt;A prototype of Google+&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://foundation.zurb.com/grid-example1.php'&gt;All grid sizes&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://foundation.zurb.com/grid-example2.php'&gt;Nesting the grid&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://foundation.zurb.com/mobile-example1.php'&gt;The mobile grid&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id='links'&gt;Links&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='http://foundation.zurb.com/'&gt;ZURB Foundation&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='https://github.com/zurb/foundation-sass'&gt;Foundation Sass&lt;/a&gt; on GitHub&lt;/li&gt;

&lt;li&gt;&lt;a href='http://foundation.zurb.com/docs/'&gt;Foundation Docs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content>
    <published>2011-12-22T14:30:00-06:00</published>
    <updated>2011-12-22T14:30:00-06:00</updated>
    <category term="adam-stacoviak" />
    <category term="projects" />
  </entry>
  <entry>
    <title>Responsive Web Design in Sass Part 2: Media Queries in Sass</title>
    <link href="http://thesassway.com/intermediate/responsive-web-design-part-2" rel="alternate" type="text/html" />
    <id>tag:thesassway.com,2011-12-02:/intermediate/responsive-web-design-part-2</id>
    <content type="html">&lt;div class='editors-note'&gt;

  &lt;h4&gt;EDITOR'S NOTE&lt;/h4&gt;
  &lt;p&gt;Mason followed up this article with &lt;a href='http://thesassway.com/intermediate/responsive-web-design-in-sass-using-media-queries-in-sass-32'&gt;Responsive Web Design in Sass: Using Media Queries in Sass 3.2&lt;/a&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;p&gt;In &lt;a href='http://thesassway.com/intermediate/responsive-web-design-part-1'&gt;part one&lt;/a&gt; we talked about how Sass can help with fluid layouts and images. Now we&amp;#8217;ll turn our attention to the new kid in town. Media queries are the tool that takes a design from fluid to truly responsive.&lt;/p&gt;

&lt;h2 id='i_resisted_fluid_layouts_too'&gt;I Resisted Fluid Layouts (too)&lt;/h2&gt;

&lt;p&gt;Fluid or elastic layouts allow your site&amp;#8217;s content to grow and shrink to fit the screen, so that solves the problem right? OK. See you later.&lt;/p&gt;

&lt;p&gt;I didn&amp;#8217;t think so either. As much as I wanted to, I just couldn&amp;#8217;t get on board with all the rage of fluid and elastic layouts. Personally, I resisted them for for one primary reason.&lt;/p&gt;

&lt;p&gt;Not &lt;strong&gt;&lt;em&gt;all&lt;/em&gt;&lt;/strong&gt; layouts work at &lt;strong&gt;&lt;em&gt;all&lt;/em&gt;&lt;/strong&gt; sizes.&lt;/p&gt;

&lt;p&gt;When a layout of mine grew or shrank outside the &amp;#8220;sweet spot&amp;#8221; of my design I felt that it usually ruined the balance and composition of the design. At least when I made a fixed layout I could place the burden of having a big enough screen on the user.&lt;/p&gt;

&lt;p&gt;It&amp;#8217;s clear to me now that with the explosion of newly connected devices, placing the burden of having the right size screen on the user is no longer a suitable solution. It&amp;#8217;s a recipe for failure.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::html&amp;#x000A;&amp;lt;q class=&amp;quot;smug-designer&amp;quot;&amp;gt;&amp;#x000A;  &amp;quot;It wasn&amp;#39;t &amp;lt;em&amp;gt;my&amp;lt;/em&amp;gt; fault they were on a netbook.&amp;#x000A;  I&amp;#39;m concerned with &amp;quot;mainstream&amp;quot; (desktop) users.&amp;quot;&amp;#x000A;&amp;lt;/q&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But, I knew designing to a fixed layout was a cheat and I hated horizontal scroll bars as much as my users and clients did. I just didn&amp;#8217;t know of a way to do fluid layouts without compromising my design.&lt;/p&gt;

&lt;p&gt;And then, my jaw dropped along with all the other web nerds when I read &lt;a href='http://www.alistapart.com/articles/responsive-web-design/'&gt;Ethan Marcotte’s article&lt;/a&gt; on A List Apart. All hail media queries!&lt;/p&gt;

&lt;h2 id='what_are_media_queries_and_why_should_i_care'&gt;What are media queries and why should I care?&lt;/h2&gt;

&lt;p&gt;If you&amp;#8217;ve ever created a print style sheet you&amp;#8217;ve used media-specific CSS. In that case you called a separate CSS file just for print by setting the &lt;code&gt;media&lt;/code&gt; attribute of a link:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::html&amp;#x000A;&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;paper.css&amp;quot; media=&amp;quot;print&amp;quot; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This gave us some control over media types, but that&amp;#8217;s it. Then CSS3 introduced the concept of using a query in that space as well. You can add your query in the &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; tag, or join the cool kids and use the &lt;code&gt;@media&lt;/code&gt; rule in CSS. More on that later.&lt;/p&gt;

&lt;p&gt;First let&amp;#8217;s look at what kind of queries we can write. If you look at the &lt;a href='http://www.w3.org/TR/css3-mediaqueries/#media1'&gt;W3C Spec&lt;/a&gt; you&amp;#8217;ll see a dazzling array of different properties you can check. The ones I&amp;#8217;m most interested in are the ones concerning width, height, orientation, and ratio. By swapping out different rules based on these properties you can change the size and shape of your design to truly fit the viewing area.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s a simple query in the &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; tag that will load a css file for small screens.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::html&amp;#x000A;&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; media=&amp;quot;screen and (max-width: 480px)&amp;quot; href=&amp;quot;small.css&amp;quot; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This is great, but if we want to manage a lot of different options these files can add up quickly. Fortunately we have the &lt;code&gt;@media&lt;/code&gt; rule. You can use these inside any CSS file to apply specific rules only when the query expression is true.&lt;/p&gt;

&lt;p&gt;Here I&amp;#8217;m setting the &lt;code&gt;font-size&lt;/code&gt; of an &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; to be larger on a large screen.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::scss&amp;#x000A;// set a variable for the font size&amp;#x000A;$h1-size: 36px&amp;#x000A;&amp;#x000A;h1 {&amp;#x000A;  font-size: $h1-size;&amp;#x000A;}&amp;#x000A;&amp;#x000A;// this will only affect wide screens&amp;#x000A;@media screen and (min-width: 1024px) {&amp;#x000A;  h1 {&amp;#x000A;    font-size: $h1-size * 1.5;&amp;#x000A;  }&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Which compiles to:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::css&amp;#x000A;h1 {&amp;#x000A;  font-size: 36px;&amp;#x000A;}&amp;#x000A;@media screen and (min-width: 1024px) {&amp;#x000A;  h1 {&amp;#x000A;    font-size: 54px;&amp;#x000A;  }&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can use these in Sass just fine, and inside a query you can use all the Sass features you like. In the above example I used and manipulated a variable. You should note, however, that you can&amp;#8217;t use variables in the query declaration itself. It would be nice to write the following, but it won&amp;#8217;t work.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::scss&amp;#x000A;$breakpoint: 1024px;&amp;#x000A;&amp;#x000A;@media screen and (min-width: $breakpoint) {&amp;#x000A;  content: &amp;quot;this won&amp;#39;t work :(&amp;quot;;&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;em&gt;&lt;a href='#the_future_of_media_queries_in_sass'&gt;Skip ahead&lt;/a&gt; to see how the upcoming Sass 3.2 release will help with this.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id='media_bubbling'&gt;@media Bubbling&lt;/h2&gt;

&lt;p&gt;Sass does provide what I consider to be a pretty &lt;strong&gt;&lt;em&gt;killer feature&lt;/em&gt;&lt;/strong&gt; for authoring @media when you nest them inside other selectors. If you add a @media query by nesting it inside a selector Sass will &amp;#8220;bubble&amp;#8221; that @media query and the new rule outside of the nest and back out to the root of your style sheet.&lt;/p&gt;

&lt;p&gt;I use @media un-nested (as mentioned above) when I&amp;#8217;m setting up large-scale changes like a responsive master grid, but I find that I need to make small adjustments much more often. For example, lets say you have a profile picture that looks great large and floated to the left on a desktop, but needs to shrink on a smaller screen. It also needs to stop floating on a really wide screen.&lt;/p&gt;

&lt;p&gt;In Sass we can write that like this.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::scss&amp;#x000A;.profile-pic {&amp;#x000A;  float: left;&amp;#x000A;  width: 250px;&amp;#x000A;  @media screen and (max-width: 320px) {&amp;#x000A;    width: 100px;&amp;#x000A;  }&amp;#x000A;  @media screen and (min-width: 1200px) {&amp;#x000A;    float: none;&amp;#x000A;  }&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Sass will see this and know that you want to apply that query to the selector it&amp;#8217;s nested in. It compiles to CSS like so:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::css&amp;#x000A;.profile-pic {&amp;#x000A;  float: left;&amp;#x000A;  width: 250px;&amp;#x000A;}&amp;#x000A;@media screen and (max-width: 320px) {&amp;#x000A;  .profile-pic {&amp;#x000A;    width: 100px;&amp;#x000A;  }&amp;#x000A;}&amp;#x000A;@media screen and (min-width: 1200px) {&amp;#x000A;  .profile-pic {&amp;#x000A;    float: none;&amp;#x000A;  }&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I really like how this lets me keep my rules for the different options adjacent to both the original rule and to each other. It really speeds up the process, especially when you turn to the details of your responsive project.&lt;/p&gt;

&lt;p&gt;When I was designing the homepage for &lt;a href='http://thecodingdesigner.com/'&gt;The Coding Designer&amp;#8217;s Survival Kit&lt;/a&gt; I made a module where the elements laid out in a circle that took up a lot of space in the wide screen version of the design. However in any width lower than 900px they overflowed the boundary and the circle no longer made sense. In this case the best design decision was to lay those elements out in another way, and I chose a grid. If you&amp;#8217;re curious you can &lt;a href='https://github.com/canarymason/The-Coding-Designer-s-Survival-Kit-Site/blob/master/sites/all/themes/badge/css/src/_design.sass#L328'&gt;view my source&lt;/a&gt; sass for that project.&lt;/p&gt;

&lt;h2 id='the_future_of_media_queries_in_sass'&gt;The Future of Media Queries in Sass&lt;/h2&gt;
&lt;div class='editors-note'&gt;

  &lt;h4&gt;EDITOR'S NOTE&lt;/h4&gt;
  &lt;p&gt;Mason followed up this article with &lt;a href='http://thesassway.com/intermediate/responsive-web-design-in-sass-using-media-queries-in-sass-32'&gt;Responsive Web Design in Sass: Using Media Queries in Sass 3.2&lt;/a&gt;&lt;/p&gt;

&lt;/div&gt;
&lt;p&gt;Sass 3.2 is about to make all this calculating absolutely trivial. At the moment, Sass 3.2 is only available as &lt;a href='https://rubygems.org/gems/sass/versions/3.2.0.alpha.35'&gt;an Alpha release&lt;/a&gt;. There&amp;#8217;s &lt;a href='https://github.com/nex3/sass/issues/milestones'&gt;a milestone&lt;/a&gt; on &lt;a href='https://github.com/nex3'&gt;Sass&amp;#8217;s GitHub project&lt;/a&gt; as well that&amp;#8217;s at the 33% mark.&lt;/p&gt;

&lt;p&gt;In my examples above you may have noticed that all the media queries were written out and included the pixel value for each break point, in every media query I used. &amp;#8220;What? Where are the variables?&amp;#8221;, you asked? Well it turns out that until 3.2, which is yet to be released, Sass didn&amp;#8217;t support variables in media queries. Well, strictly speaking it still doesn&amp;#8217;t. But, Sass 3.2 introduces the ability to pass content blocks to functions. Chris Eppstein &lt;a href='https://gist.github.com/1215856#file_6_media_queries.scss'&gt;published a gist&lt;/a&gt; showing how you might use this. I&amp;#8217;ll use these new mixins to redo my profile picture example:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::scss&amp;#x000A;@mixin respond-to($media) {&amp;#x000A;  @if $media == handhelds {&amp;#x000A;    @media only screen and (max-width: 320px) { @content; }&amp;#x000A;  }&amp;#x000A;  @else if $media == medium-screens {&amp;#x000A;    @media only screen and (min-width: 321px) and (max-width: 1024px) { @content; }&amp;#x000A;  }&amp;#x000A;  @else if $media == wide-screens {&amp;#x000A;    @media only screen and (min-width: 1024px) { @content; }&amp;#x000A;  }&amp;#x000A;}&amp;#x000A;&amp;#x000A;.profile-pic {&amp;#x000A;  float: left;&amp;#x000A;  width: 250px;&amp;#x000A;  @include respond-to(handhelds) { width: 100% ;}&amp;#x000A;  @include respond-to(medium-screens) { width: 125px; }&amp;#x000A;  @include respond-to(wide-screens) { float: none; }&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And the compiled css:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::css&amp;#x000A;.profile-pic {&amp;#x000A;  float: left;&amp;#x000A;  width: 250px;&amp;#x000A;}&amp;#x000A;@media only screen and (max-width: 320px) {&amp;#x000A;  .profile-pic {&amp;#x000A;    width: 100%;&amp;#x000A;  }&amp;#x000A;}&amp;#x000A;@media only screen and (min-width: 321px) and (max-width: 1024px) {&amp;#x000A;  .profile-pic {&amp;#x000A;    width: 125px;&amp;#x000A;  }&amp;#x000A;}&amp;#x000A;@media only screen and (min-width: 1024px) {&amp;#x000A;  .profile-pic {&amp;#x000A;    float: none;&amp;#x000A;  }&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This makes it possible to set up a mixin for all your @media breakpoints and reuse that as often as you need. This makes it incredibly easy to keep track of all the different ways your styles may fracture as you do specific styling in each breakpoint. I have to say it got me salivating. I can tell you are too. Once that feature is in place we should be able to create some very smart mixins and templates for media queries (and other tricks too!) and responsive grid frameworks.&lt;/p&gt;

&lt;h3 id='sass_32_alpha'&gt;Sass 3.2 Alpha&lt;/h3&gt;

&lt;p&gt;You can try out the new Sass 3.2 features I&amp;#8217;ve talked about in this article before its official release by installing it with this command:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;gem install sass --pre&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Or, if you use &lt;a href='http://gembundler.com/'&gt;Bundler&lt;/a&gt;, simply add this to your &lt;code&gt;Gemfile&lt;/code&gt; and &lt;code&gt;bundle install&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;gem &amp;quot;sass&amp;quot;, &amp;quot;~&amp;gt; 3.2.0.alpha.35&amp;quot;&lt;/code&gt;&lt;/pre&gt;</content>
    <published>2011-12-02T17:00:00-06:00</published>
    <updated>2011-12-02T17:00:00-06:00</updated>
    <category term="guides" />
    <category term="intermediate" />
    <category term="mason-wendell" />
  </entry>
  <entry>
    <title>Interactive Sass: Having Fun On The Terminal</title>
    <link href="http://thesassway.com/intermediate/interactive-sass-having-fun-on-the-terminal" rel="alternate" type="text/html" />
    <id>tag:thesassway.com,2011-11-22:/intermediate/interactive-sass-having-fun-on-the-terminal</id>
    <content type="html">&lt;p&gt;Most people who use Sass are familiar to some degree with the command line. While programs like &lt;a href='http://compass.handlino.com/'&gt;Compass.app&lt;/a&gt; and &lt;a href='http://mhs.github.com/scout-app/'&gt;Scout.app&lt;/a&gt; are making it easier to use Sass and Compass without using the command line, hidden gems await those who are willing to do so.&lt;/p&gt;

&lt;h2 id='the_interactive_sass_interpreter'&gt;The Interactive Sass Interpreter&lt;/h2&gt;

&lt;p&gt;One of these little gems is the interactive Sass interpreter. Many modern programming languages (like Python and Ruby) ship with an interactive version that can be used from the command prompt. These programs read a line of code in from the user, evaluate it, and output the result. It&amp;#8217;s called a Read-Eval-Print loop, also known as &lt;a href='http://en.wikipedia.org/wiki/Read–eval–print_loop'&gt;REPL&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To use the interactive interpreter for Sass, open up the &lt;a href='http://wiseheartdesign.com/articles/2010/11/12/the-designers-guide-to-the-osx-command-prompt/'&gt;command prompt&lt;/a&gt; and type:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash&amp;#x000A;sass --interactive&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Or, if you like, use the short version of the same command:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::bash&amp;#x000A;sass -i&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Once started in interactive mode, the &lt;code&gt;sass&lt;/code&gt; command will output a prompt &amp;#8221;&amp;#187;&amp;#8221; asking for input. Enter any valid &lt;a href='http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#sassscript'&gt;Sass Script&lt;/a&gt; expression and it will output the result on the line below:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt; 12 * 4 - 6&amp;#x000A;42&amp;#x000A;&amp;gt;&amp;gt; 1px + 1px + 1px&amp;#x000A;3px&amp;#x000A;&amp;gt;&amp;gt; lighten(#333, 10%)&amp;#x000A;#4d4d4d&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;em&gt;Sass Script&lt;/em&gt; is a small subset of the Sass language. It mostly includes the mathematical parts of Sass and functions. You can&amp;#8217;t use Sass features like mixins or variables. But even with this small amount of functionality, you can still use interactive Sass to learn some interesting things about the Sass language. For instance:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt; 1em + 1px&amp;#x000A;SyntaxError: Incompatible units: &amp;#39;em&amp;#39; and &amp;#39;px&amp;#39;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Oh! That should have been obvious. Sass has no way of adding ems and pixels. So it will throw an error if you try to add them.&lt;/p&gt;

&lt;p&gt;And this one:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt; #333 + #666&amp;#x000A;#999999&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Wow! Did you know that you can add colors in Sass? And that&amp;#8217;s not all, you can also subtract, multiply and divide!&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt; #999 - #333&amp;#x000A;#666666&amp;#x000A;&amp;gt;&amp;gt; #333 * #030303&amp;#x000A;#999999&amp;#x000A;&amp;gt;&amp;gt; #999 / #030303&amp;#x000A;#333333&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now I don&amp;#8217;t use color math with Sass every day, mostly because Sass color functions have replaced the need for it, but you can get an idea of how they work using interactive Sass.&lt;/p&gt;

&lt;p&gt;Speaking of Sass color functions, I often use interactive Sass to reduce a series of complex color functions to a color value:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt; saturate(#113, 10%)&amp;#x000A;#0e0e36&amp;#x000A;&amp;gt;&amp;gt; adjust-hue(green, 10deg)&amp;#x000A;#008015&amp;#x000A;&amp;gt;&amp;gt; adjust-color(blue, $lightness: -20%, $hue: 20deg)&amp;#x000A;#330099&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This allows me to design in the browser tweaking color values with functions. When I arrive at a color I like, I can simplify it to it&amp;#8217;s actual color value using the &lt;code&gt;sass&lt;/code&gt; command in interactive mode.&lt;/p&gt;

&lt;p&gt;To quit once you&amp;#8217;ve entered interactive mode, just type &lt;code&gt;Ctrl+D&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id='conclusion'&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;As you can see, the interactive Sass interpreter is an nice way to play with many Sass Script functions, math, color functions and more. If you&amp;#8217;re a Compass user (as you should be), it&amp;#8217;s also worth mentioning Compass includes it&amp;#8217;s own version of interactive Sass which will give you access to an array of additional functions that Compass provides. Just execute &lt;code&gt;compass interactive&lt;/code&gt; on the command prompt.&lt;/p&gt;</content>
    <published>2011-11-22T09:30:00-06:00</published>
    <updated>2011-11-22T09:30:00-06:00</updated>
    <category term="guides" />
    <category term="intermediate" />
    <category term="john-w-long" />
  </entry>
  <entry>
    <title>How Sass Can Shape The Future of CSS</title>
    <link href="http://thesassway.com/articles/how-sass-can-shape-the-future-of-css" rel="alternate" type="text/html" />
    <id>tag:thesassway.com,2011-11-20:/articles/how-sass-can-shape-the-future-of-css</id>
    <content type="html">&lt;p&gt;The rise in popularity of CSS extensions, such as Sass, in recent years has not gone unnoticed by the people who work on proposing and standardizing modules for CSS3 (and CSS4).&lt;/p&gt;

&lt;h2 id='sass_features_being_adapted_for_submission'&gt;Sass Features Being Adapted for Submission&lt;/h2&gt;

&lt;p&gt;Many of the key features found in Sass are being adapted for submission to the W3C. &lt;a href='http://www.xanthir.com/blog/b49w0'&gt;Variables, Mixins, and Nesting are all mooted for inclusion in CSS&lt;/a&gt;, and we may see some of them appear in the near future.&lt;/p&gt;

&lt;p&gt;Then again, we may not; resistance to the proposals is quite strong from certain members - for example, &lt;a href='http://www.w3.org/People/Bos/'&gt;Bert Bos&lt;/a&gt; wrote a long article on &lt;a href='http://www.w3.org/People/Bos/CSS-variables'&gt;why he considers CSS Variables to be harmful&lt;/a&gt;. But I thought it would be interesting for the Sass community to see how the software to which you develop and contribute to (Sass) is being used to discuss the future of the web.&lt;/p&gt;

&lt;h2 id='the_variables_proposal'&gt;The Variables Proposal&lt;/h2&gt;

&lt;p&gt;This proposal should look very familiar to you - it&amp;#8217;s the same syntax that Sass uses, with one addition. Each variable is defined using a three-part syntax: first you set up the declaration using the &lt;code&gt;@var&lt;/code&gt; at-rule, then you provide a unique name with the &lt;code&gt;$&lt;/code&gt; character before it, then you set the value:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::css&amp;#x000A;@var $foo #F00;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Once set up like this, you can reference your variable by using the unique name as a value:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::css&amp;#x000A;h1 { color: $foo; }&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;a href='http://www.xanthir.com/blog/b4AD0'&gt;This proposal has already been put forward to the W3C&lt;/a&gt;, and I&amp;#8217;ll tell you the result of that shortly.&lt;/p&gt;

&lt;h2 id='the_mixins_proposal'&gt;The Mixins Proposal&lt;/h2&gt;

&lt;p&gt;As with Variables, you should be very familiar with the Mixins proposal - the syntax used in Sass was the inspiration. You create a declaration block using the @mixin at-rule, assign a unique id, and then add your rules:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::scss&amp;#x000A;@mixin foo { color: #F00; font-weight: bold; }&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;When you need to use that code block you call it using the @mix directive and the unique id you previously assigned:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::css&amp;#x000A;h1 { font-size: 2em; @mix foo; }&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As you can see, the only difference is that the CSS proposal uses &lt;code&gt;@mix&lt;/code&gt; in place of Sass&amp;#8217;s &lt;code&gt;@include&lt;/code&gt;. As with Sass, you can also use parameters with Mixins:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::css&amp;#x000A;@mixin foo($bar #F00) {&amp;#x000A;  border-color: $bar;&amp;#x000A;  color: $bar;&amp;#x000A;}&amp;#x000A;h1 {&amp;#x000A;  @mix foo(#00F);&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id='an_alternative_variables_syntax'&gt;An Alternative Variables Syntax&lt;/h2&gt;

&lt;p&gt;Recently, &lt;a href='http://lists.w3.org/Archives/Public/www-style/2011Oct/0699.html'&gt;an alternative syntax for Variables has been proposed&lt;/a&gt;. This syntax looks and acts somewhat similarly to the HTML data attribute, although it&amp;#8217;s not the same. In this proposal variables are scoped to elements (for global scope, you&amp;#8217;d use the &lt;code&gt;:root&lt;/code&gt; selector) and the variable name is prefixed with &lt;code&gt;data-&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::css&amp;#x000A;:root {&amp;#x000A;  data-foo: #F00;&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then you reference the variable by using the unique name in the data function:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::css&amp;#x000A;h1 {&amp;#x000A;  color: data(foo);&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This has the advantage of allowing scoped variables, and integrating better with the &lt;a href='http://dev.w3.org/csswg/cssom/'&gt;CSSOM&lt;/a&gt;, JavaScript, as well as inspector tools like &lt;a href='http://getfirebug.com/'&gt;Firebug&lt;/a&gt; or &lt;a href='http://www.opera.com/dragonfly/'&gt;Dragonfly&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It must be stressed&lt;/strong&gt;, however, that this is &lt;strong&gt;still only&lt;/strong&gt; at the discussion stage.&lt;/p&gt;

&lt;h3 id='so_when_will_we_see_them'&gt;So When Will We See Them?&lt;/h3&gt;

&lt;p&gt;As I said, maybe never. As I understand it, the first Variables proposal was not well received by the W3C - but the module author, &lt;a href='https://twitter.com/#!/tabatkins'&gt;Tab Atkins&lt;/a&gt;, is continuing to refine it anyway. Tab is also key to the creation of the alternative syntax. You can follow along with Tab and his writing at &lt;a href='http://www.xanthir.com/blog/'&gt;his personal blog&lt;/a&gt; where he shares his thoughts on web standards as well as details surrounding discussions on the future of CSS.&lt;/p&gt;

&lt;p&gt;As for Mixins, they were rejected out of hand and probably won&amp;#8217;t be pursued. The reason given? Lack of use cases. But I can&amp;#8217;t imagine that you, as Sass creators, developers and users are short of use cases for Mixins. So, if you have them I&amp;#8217;d love to read them - please leave a comment below sharing your thoughts if that&amp;#8217;s the case.&lt;/p&gt;

&lt;p&gt;If work does continue on these proposals, or any part of them, I think that it would be &lt;em&gt;a matter of little time&lt;/em&gt; before browsers started to implement them; I believe, in fact, that &lt;a href='http://www.webkit.org/'&gt;WebKit&lt;/a&gt; already implemented Variables, only to remove them after feedback from the &lt;a href='http://www.w3.org/'&gt;W3C&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id='conclusion'&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;I have to confess that I&amp;#8217;ve only briefly experimented with Sass, and have not used it in any production websites, but what I like about it is the ease with which it&amp;#8217;s been possible to adapt the syntax into CSS itself. It&amp;#8217;s great to see community-created language extensions influence the evolution of the web, and even if none of these proposals ever make it to the implementation stage, you can be sure that &lt;strong&gt;&lt;em&gt;at the very least&lt;/em&gt;&lt;/strong&gt; they form part of the standards conversation.&lt;/p&gt;

&lt;h2 id='links'&gt;Links&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href='http://www.xanthir.com/blog/b49w0'&gt;CSSOM, Vars, Mixins, Nesting, and Modules&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://www.w3.org/People/Bos/CSS-variables'&gt;Why “variables” in CSS are harmful&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://www.xanthir.com/blog/b4AD0'&gt;CSS Variables Draft&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href='http://lists.w3.org/Archives/Public/www-style/2011Oct/0699.html'&gt;Better Variables through Custom Properties from Tab Atkins Jr. on 2011-10-24&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content>
    <published>2011-11-20T20:00:00-06:00</published>
    <updated>2011-11-20T20:00:00-06:00</updated>
    <category term="articles" />
    <category term="peter-gasston" />
  </entry>
  <entry>
    <title>Nested Selectors: The Inception Rule</title>
    <link href="http://thesassway.com/beginner/the-inception-rule" rel="alternate" type="text/html" />
    <id>tag:thesassway.com,2011-11-20:/beginner/the-inception-rule</id>
    <content type="html">&lt;p&gt;It&amp;#8217;s well known that Sass is an &lt;em&gt;efficient&lt;/em&gt;, &lt;em&gt;realiable&lt;/em&gt; and &lt;em&gt;precise&lt;/em&gt; tool which gives us great power and freedom to make CSS fun and less of a pain to author; however with great power comes &lt;em&gt;responsibility&lt;/em&gt;.&lt;/p&gt;

&lt;h2 id='the_problem'&gt;The Problem&lt;/h2&gt;

&lt;p&gt;We&amp;#8217;ve all been there, in the CSS realm, where all code lives at a &amp;#8220;root level&amp;#8221; and writing nested selectors means writing a lot of code for each CSS declaration.&lt;/p&gt;

&lt;p&gt;Today we&amp;#8217;re going to dive into the most basic rule in the Sass universe. It&amp;#8217;s called, &amp;#8220;The Inception Rule.&amp;#8221; This rule will help you survive &lt;a href='http://37signals.com/svn/posts/3003-css-taking-control-of-the-cascade'&gt;the most common mistake&lt;/a&gt; that many Sass developers, beginners and advanced make.&lt;/p&gt;

&lt;p&gt;Take this code for example:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::css&amp;#x000A;.post {&amp;#x000A;  border-radius: 3px;&amp;#x000A;  background: #FFF8FF;&amp;#x000A;  border: 1px solid #EFC6F3;&amp;#x000A;  padding: 15px;&amp;#x000A;  color: #333333;&amp;#x000A;}&amp;#x000A;.post .title, .post .alt-title  {&amp;#x000A;  color: #000000;&amp;#x000A;  font-size:20px;&amp;#x000A;}&amp;#x000A;.post .alt-title {&amp;#x000A;  border-bottom:1px solid #EFC6F3;&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Odds are that while you were stuck in the CSS realm you began taking the approach of making loads of classes and then stuffing them in your HTML like no tomorrow. Have you ever added 5 classes to a single DOM element?&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::html&amp;#x000A;&amp;lt;div class=&amp;quot;post complete highlight rounded clearfix&amp;quot;&amp;gt;...&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That was the everyday bread and butter. We all thought we wouldn&amp;#8217;t be able to enjoy writing CSS. However, as soon as Sass appeared in your life, you discovered this was &lt;strong&gt;the way&lt;/strong&gt; to go when working with CSS.&lt;/p&gt;

&lt;p&gt;And just as easy as it is to get going with Sass, it&amp;#8217;s also easy to use it incorrectly.&lt;/p&gt;

&lt;p&gt;When you begin working with Sass, the first feature you fall in love with is &amp;#8220;nested selectors&amp;#8221;. Being able to nest selectors under another is a wonderful feature which saves keystrokes and possibly Carpal Tunnel Syndrome as well.&lt;/p&gt;

&lt;p&gt;Let&amp;#8217;s look at an example of nesting selectors in Sass.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::scss&amp;#x000A;$border: 1px solid #EFC6F3;&amp;#x000A;.post {&amp;#x000A;  border-radius: 3px;&amp;#x000A;  background: #FFF8FF;&amp;#x000A;  border: 1px solid $border;&amp;#x000A;  padding: 15px;&amp;#x000A;  color: #333333;&amp;#x000A;  .title {&amp;#x000A;    color: #000000;&amp;#x000A;    font-size:20px;&amp;#x000A;  }&amp;#x000A;  .alt-title {&amp;#x000A;    @extend .title;&amp;#x000A;    border-bottom:1px solid $border;&amp;#x000A;  }&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The above code will output the exact same code as the code you didn&amp;#8217;t like to write when you were writing CSS because of all repetition.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s the output of the above Sass just so you can see how this translates to CSS.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::css&amp;#x000A;.post {&amp;#x000A;  border-radius: 3px;&amp;#x000A;  background: #FFF8FF;&amp;#x000A;  border: 1px solid 1px solid #efc6f3;&amp;#x000A;  padding: 15px;&amp;#x000A;  color: #333333;&amp;#x000A;}&amp;#x000A;.post .title, .post .alt-title {&amp;#x000A;  color: #000000;&amp;#x000A;  font-size: 20px;&amp;#x000A;}&amp;#x000A;.post .alt-title {&amp;#x000A;  border-bottom: 1px solid 1px solid #efc6f3;&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And so, like a child with a new toy, we begin to use this feature in &lt;em&gt;-what we think-&lt;/em&gt; is its &amp;#8220;max potential&amp;#8221;. But actually what&amp;#8217;s taking happening is some may call, a &amp;#8220;CSS Selector Nightmare.&amp;#8221;&lt;/p&gt;

&lt;h2 id='css_selector_nightmare'&gt;CSS Selector Nightmare&lt;/h2&gt;

&lt;p&gt;The so called &lt;strong&gt;nightmare&lt;/strong&gt; between front-end engineers is when the styles are bloated and tightly coupled to the DOM to a point where modifying anything about the structure ends up breaking the front-end.&lt;/p&gt;

&lt;p&gt;Let&amp;#8217;s look at this not-so-pretty piece of HTML.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::html&amp;#x000A;&amp;lt;body&amp;gt;&amp;#x000A;  &amp;lt;div class=&amp;quot;container&amp;quot;&amp;gt;&amp;#x000A;    &amp;lt;div class=&amp;quot;content&amp;quot;&amp;gt;&amp;#x000A;      &amp;lt;div class=&amp;quot;articles&amp;quot;&amp;gt;&amp;#x000A;        &amp;lt;div class=&amp;quot;post&amp;quot;&amp;gt;&amp;#x000A;          &amp;lt;div class=&amp;quot;title&amp;quot;&amp;gt;&amp;#x000A;            &amp;lt;h1&amp;gt;&amp;lt;a href=&amp;quot;#&amp;quot;&amp;gt;Hello World&amp;lt;/a&amp;gt;&amp;#x000A;          &amp;lt;/div&amp;gt;&amp;#x000A;          &amp;lt;div class=&amp;quot;content&amp;quot;&amp;gt;&amp;#x000A;            &amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;&amp;#x000A;            &amp;lt;ul&amp;gt;&amp;#x000A;              &amp;lt;li&amp;gt;...&amp;lt;/li&amp;gt;&amp;#x000A;            &amp;lt;/ul&amp;gt;&amp;#x000A;          &amp;lt;/div&amp;gt;&amp;#x000A;          &amp;lt;div class=&amp;quot;author&amp;quot;&amp;gt;&amp;#x000A;            &amp;lt;a href=&amp;quot;#&amp;quot; class=&amp;quot;display&amp;quot;&amp;gt;&amp;lt;img src=&amp;quot;...&amp;quot; /&amp;gt;&amp;lt;/a&amp;gt;&amp;#x000A;            &amp;lt;h4&amp;gt;&amp;lt;a href=&amp;quot;#&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&amp;lt;/h4&amp;gt;&amp;#x000A;            &amp;lt;p&amp;gt;&amp;#x000A;              &amp;lt;a href=&amp;quot;#&amp;quot;&amp;gt;...&amp;lt;/a&amp;gt;&amp;#x000A;              &amp;lt;ul&amp;gt;&amp;#x000A;                &amp;lt;li&amp;gt;...&amp;lt;/li&amp;gt;&amp;#x000A;              &amp;lt;/ul&amp;gt;&amp;#x000A;            &amp;lt;/p&amp;gt;&amp;#x000A;          &amp;lt;/div&amp;gt;&amp;#x000A;        &amp;lt;/div&amp;gt;&amp;#x000A;      &amp;lt;/div&amp;gt;&amp;#x000A;&amp;#x000A;    &amp;lt;/div&amp;gt;&amp;#x000A;  &amp;lt;/div&amp;gt;&amp;#x000A;&amp;lt;/body&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Because Sass offers you the ability to nest your selectors, and you know that having your code encapsulated is the &amp;#8220;good way to avoid collisions with other styles&amp;#8221;, you might find yourself mimicking the DOM in your Sass (bad idea).&lt;/p&gt;

&lt;p&gt;Let&amp;#8217;s look at some Sass you might craft for our not-so-pretty piece of HTML.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::scss&amp;#x000A;body {&amp;#x000A;  div.container {&amp;#x000A;    div.content {&amp;#x000A;      div.articles {&amp;#x000A;        &amp;amp; &amp;gt; div.post {&amp;#x000A;          div.title {&amp;#x000A;            h1 {&amp;#x000A;              a {&amp;#x000A;              }&amp;#x000A;            }&amp;#x000A;          }&amp;#x000A;          div.content {&amp;#x000A;            p { ... }&amp;#x000A;            ul {&amp;#x000A;              li { ... }&amp;#x000A;            }&amp;#x000A;          }&amp;#x000A;          div.author {&amp;#x000A;            a.display {&amp;#x000A;              img { ... }&amp;#x000A;            }&amp;#x000A;            h4 {&amp;#x000A;              a { ... }&amp;#x000A;            }&amp;#x000A;            p {&amp;#x000A;              a { ... }&amp;#x000A;            }&amp;#x000A;            ul {&amp;#x000A;              li { ... }&amp;#x000A;            }&amp;#x000A;          }&amp;#x000A;        }&amp;#x000A;      }&amp;#x000A;    }&amp;#x000A;  }&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This is &amp;#8220;all good&amp;#8221;, right? Using the above code, you can predict 100% of the time what&amp;#8217;s going to happen with your stylesheet. There is &lt;em&gt;no cascading&lt;/em&gt; that can beat the &lt;a href='http://www.htmldog.com/guides/cssadvanced/specificity/'&gt;specificity&lt;/a&gt; &amp;#8230;&lt;/p&gt;

&lt;p&gt;After compiling the Sass, we take a look at the result on to find that we&amp;#8217;ve created a CSS monster. Ugh!&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::css&amp;#x000A;body { ... }&amp;#x000A;body div.content div.container { ... }&amp;#x000A;body div.content div.container div.articles { ... }&amp;#x000A;body div.content div.container div.articles &amp;gt; div.post { ... }&amp;#x000A;body div.content div.container div.articles &amp;gt; div.post div.title { ... }&amp;#x000A;body div.content div.container div.articles &amp;gt; div.post div.title h1 { ... }&amp;#x000A;body div.content div.container div.articles &amp;gt; div.post div.title h1 a { ... }&amp;#x000A;body div.content div.container div.articles &amp;gt; div.post div.content { ... }&amp;#x000A;body div.content div.container div.articles &amp;gt; div.post div.content p { ... }&amp;#x000A;body div.content div.container div.articles &amp;gt; div.post div.content ul { ... }&amp;#x000A;body div.content div.container div.articles &amp;gt; div.post div.content ul li { ... }&amp;#x000A;body div.content div.container div.articles &amp;gt; div.post div.author { ... }&amp;#x000A;body div.content div.container div.articles &amp;gt; div.post div.author a.display { ... }&amp;#x000A;body div.content div.container div.articles &amp;gt; div.post div.author a.display img { ... }&amp;#x000A;body div.content div.container div.articles &amp;gt; div.post div.author h4 { ... }&amp;#x000A;body div.content div.container div.articles &amp;gt; div.post div.author h4 a { ... }&amp;#x000A;body div.content div.container div.articles &amp;gt; div.post div.author p { ... }&amp;#x000A;body div.content div.container div.articles &amp;gt; div.post div.author p a { ... }&amp;#x000A;body div.content div.container div.articles &amp;gt; div.post div.author ul { ... }&amp;#x000A;body div.content div.container div.articles &amp;gt; div.post div.author ul li { ... }&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;There are so many reasons why this is just plain &lt;strong&gt;wrong&lt;/strong&gt;, from &lt;a href='http://code.google.com/speed/page-speed/docs/rendering.html#UseEfficientCSSSelectors'&gt;rendering performance&lt;/a&gt; to file-size performance. Just think about how many bytes this will add to your CSS. But, the odds are you may say:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&amp;#8220;Hey, computers are faster now! and also the internet download speeds are better!&amp;#8221; - User who hates Front-End Engineering.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But that&amp;#8217;s not the only problem! Since your styles are so specific to the DOM, &lt;em&gt;maintainability&lt;/em&gt; is now a problem.&lt;/p&gt;

&lt;p&gt;Any change you make to your markup will need to be reflected into your Sass and vice versa. It also means that the styles are bounded for life to the those elements and that HTML structure which completely defeats the purpose of the &amp;#8220;Cascade&amp;#8221; part of &amp;#8220;Cascading Style Sheets.&amp;#8221;&lt;/p&gt;

&lt;p&gt;If you follow this path, you might as well go back to writing your CSS inline in your HTML (please don&amp;#8217;t).&lt;/p&gt;

&lt;h2 id='meet_the_inception_rule'&gt;Meet The Inception Rule&lt;/h2&gt;

&lt;p&gt;To prevent you from falling into this nightmare, I created a simple rule. Until now, this rule has remained unwritten, but many followed.&lt;/p&gt;

&lt;p&gt;The Inception Rule: &lt;strong&gt;don’t go more than four levels deep&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This basically means that you shouldn&amp;#8217;t be too specific or mimicking the DOM at any point. If you find yourself more than four levels deep, that&amp;#8217;s a red flag. Of course there are times when you&amp;#8217;ll be forced to go there, but it&amp;#8217;s not something you should be doing too much.&lt;/p&gt;

&lt;h2 id='making_it_fit_in_the_four_or_less_principle'&gt;Making it fit in the Four or Less principle.&lt;/h2&gt;

&lt;p&gt;Once you understand the problem behind being too specific with selectors, you need to understand how to make your code more general by improving your understanding of &lt;em&gt;contexts&lt;/em&gt;, &lt;em&gt;objects&lt;/em&gt; and &lt;em&gt;interaction states&lt;/em&gt;.&lt;/p&gt;

&lt;h3 id='site_context'&gt;Site Context&lt;/h3&gt;

&lt;p&gt;If you&amp;#8217;re styling something that lacks completely of classes or ids, then odds are you&amp;#8217;re going to need at most just one level. Good examples of this would be the default styling of &lt;code&gt;h1 - h6&lt;/code&gt;, &lt;code&gt;ul&lt;/code&gt;, &lt;code&gt;p&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;There may be cases where it makes sense to add several selectors such as a CSS reset. Please, use common sense when crafting site context styles.&lt;/p&gt;

&lt;h3 id='page_context_layouts_sidebar_widths_heights'&gt;Page Context (layouts, sidebar widths, heights)&lt;/h3&gt;

&lt;p&gt;If you&amp;#8217;re styling the layout (sidebar and content dimensions, elements that vary depending on the page) then you&amp;#8217;re talking about page context. Usually you&amp;#8217;ll need at least two levels of indentation to achieve this. However, remember that you should &lt;em&gt;only&lt;/em&gt; assign styles things that change on a page basis, not the objects themselves. I&amp;#8217;ll cover objects in the next section.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s an example of what I mean.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::scss&amp;#x000A;.cart {&amp;#x000A;  #sidebar { width: 150px; }&amp;#x000A;  #content { width: 850px; }&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id='objects'&gt;Objects&lt;/h3&gt;

&lt;p&gt;An object is an element, alone or with children, that is identified by a &lt;code&gt;class&lt;/code&gt; or an &lt;code&gt;id&lt;/code&gt;. Usually, this is going to be the most common type of styling you should have in your code. Objects can be anything that should be delivered to the view as a whole. You can use objects as basic styling and then modify them using &amp;#8220;page context&amp;#8221; styles when needed.&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s a list of elements commonly styled as objects.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::text&amp;#x000A;#sideabr&amp;#x000A;#content&amp;#x000A;#footer&amp;#x000A;.blog-post&amp;#x000A;.comment&amp;#x000A;.widget&amp;#x000A;.logo&amp;#x000A;.user&amp;#x000A;.button&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You&amp;#8217;ll usually set one top class to identify the object and set that as a base for the selector, from there you should style using the most general selector available.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::scss&amp;#x000A;ul.special-deal {&amp;#x000A;  ...&amp;#x000A;  li {...}&amp;#x000A;  a {...}&amp;#x000A;}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note that objects should have at most 4 levels. Most of the time you&amp;#8217;ll stay around the 2-3 level range, and the fourth would be the interaction state.&lt;/p&gt;

&lt;h3 id='interaction_state'&gt;Interaction State&lt;/h3&gt;

&lt;p&gt;The interaction state covers anything that changes when you interact with an &lt;em&gt;object&lt;/em&gt;. You&amp;#8217;ll usually get close to the fourth indentation limit when adding interaction states. This is expected and is acceptable.&lt;/p&gt;

&lt;h2 id='remember'&gt;Remember&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Be smart&lt;/strong&gt;: Think about how the compiler will build your code and ask yourself if the code it&amp;#8217;s generating is really needed in your CSS. I always ask myself, can this style be achieved with less selectors?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Be crafty&lt;/strong&gt;: Use everything the compiler provides to you. For example, using the &lt;code&gt;@extend&lt;/code&gt; directive or a mixin. Each has it&amp;#8217;s own implications on the output.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Be expressive&lt;/strong&gt;: If you are adding a declaration that affects global html tags, document it with comments. Commenting your code can be huge when coming back to code weeks or months later. Comments are your friend. If you&amp;#8217;re nesting &lt;code&gt;article&lt;/code&gt; &lt;code&gt;aside&lt;/code&gt; &lt;code&gt;section&lt;/code&gt; or &lt;code&gt;h3&lt;/code&gt;, you better have a good reason!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Be creative&lt;/strong&gt;: Is there a way to make the HTML code easier to work with CSS without adding extra classes? If there is and it doesn&amp;#8217;t affect semantics. Do it. Examples of what I mean could be using adjacent selectors, targeting direct child elements and so forth. Get to know the rules of CSS before just nesting your Sass to the nth degree.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Be moderate&lt;/strong&gt;: Abusing anything is bad. Use your common sense when in doubt.&lt;/p&gt;</content>
    <published>2011-11-20T10:30:00-06:00</published>
    <updated>2011-11-20T10:30:00-06:00</updated>
    <category term="beginner" />
    <category term="guides" />
    <category term="mario-kuroir-ricalde" />
  </entry>
</feed>
