Skip to content

Instantly share code, notes, and snippets.

@codingdesigner
Created April 18, 2012 16:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codingdesigner/2414568 to your computer and use it in GitHub Desktop.
Save codingdesigner/2414568 to your computer and use it in GitHub Desktop.
Sass and Compass demo from April 17, 2012 NYC Sass meetup

Based on Survival Kit

I gave a demo last night at the first NYC Sass meetup that went over some of the key features of Sass and Compass. If you're going thru this bear in mind that the HTML is definitely overkill for this purpose, and that I'm not including any of the images in this gist. But you should get the idea.

@canarymason

<!DOCTYPE html>
<!--[if lt IE 7]> <html lang="en" class="no-js ie6"> <![endif]-->
<!--[if IE 7]> <html lang="en" class="no-js ie7"> <![endif]-->
<!--[if IE 8]> <html lang="en" class="no-js ie8"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class='no-js' lang='en'>
<!--<![endif]-->
<head>
<meta charset='utf-8' />
<title>Typography</title>
<meta content='' name='description' />
<meta content='' name='author' />
<!-- Mobile viewport optimized: j.mp/bplateviewport -->
<meta content='True' name='HandheldFriendly' />
<meta content='320' name='MobileOptimized' />
<meta content='width=device-width, target-densitydpi=160, initial-scale=1.0' name='viewport' />
<!-- For iPhone 4 with high-resolution Retina display: -->
<link href='/apple-touch-icon-114x114-precomposed.png' rel='apple-touch-icon-precomposed' sizes='114x114' />
<!-- For first-generation iPad: -->
<link href='/apple-touch-icon-72x72-precomposed.png' rel='apple-touch-icon-precomposed' sizes='72x72' />
<!-- For non-Retina iPhone, iPod Touch, and Android 2.1+ devices: -->
<link href='/apple-touch-icon-precomposed.png' rel='apple-touch-icon-precomposed' />
<!-- For Nokia -->
<link href='/apple-touch-icon.png' rel='shortcut icon' />
<!-- For everything else -->
<link href='/favicon.ico' rel='shortcut icon' />
<!-- iOS. Delete if not required -->
<meta content='yes' name='apple-mobile-web-app-capable' />
<meta content='black-translucent' name='apple-mobile-web-app-status-bar-style' />
<link href='splash.png' rel='apple-touch-startup-image' />
<!-- Microsoft. Delete if not required -->
<meta content='on' http-equiv='cleartype' />
<meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible' />
<!--[if lt IE 7 ]> <script src="//ajax.googleapis.com/ajax/libs/chrome-frame/1.0.2/CFInstall.min.js"></script><script>window.attachEvent("onload",function(){CFInstall.check({mode:"overlay"})})</script> <![endif]-->
<!-- CSS -->
<link href='/css/style.css?v=1' rel='stylesheet' />
<link href='/css/survivalkit/survivalkit.css?v=1' rel='stylesheet' />
<!-- All JavaScript at the bottom, except for Modernizr and Respond. -->
<!--[if (lt IE 9) & (!IEMobile)]>
<script src="/js/libs/selectivizr-min.js"></script>
<![endif]-->
<script src='/js/libs/modernizr-2.0.min.js'></script>
<script src='/js/libs/respond.min.js'></script>
<!-- Typekit -->
<!--
<script src='http://use.typekit.com/xxxxxxx.js' type='text/javascript'></script>
<script type='text/javascript'>
//<![CDATA[
try{Typekit.load();}catch(e){}
//]]>
</script>
-->
</head>
<body class='survival-kit'>
<div id='page'>
<header>
<hgroup>
<h1>
<a href='/survivalkit/'>The Coding Designer's Survival Kit</a>
</h1>
<h2>Typography</h2>
</hgroup>
<div class="intro">(via <a href='#credit'>Type-a-File</a>)</div>
</header>
<nav class='kit-nav'>
<ul>
<li>
<a href='/survivalkit/elements-common.html'>Common Markup</a>
</li>
<li>
<a href='/survivalkit/elements-html5.html'>Common HTML5</a>
</li>
<li>
<a href='/survivalkit/elements-typography.html'>Typography</a>
</li>
<li>
<a href='/survivalkit/elements-ui-patterns-drupal.html'>Drupal UI Patterns</a>
</li>
<!-- %li -->
<!-- %a{:href => "/survivalkit/elements-ui-patterns.html"} UI Patterns -->
<li>
<a href='/survivalkit/styletile/styletile.html'>Style Tile</a>
</li>
</ul>
</nav>
<div id='main' role='main'>
<article>
<div class="logo">The Coding Designer's Survival Kit </div>
<h1><span class='kern'>T</span>ype-a-file Gives Your Web
<span class='kern'>T</span>ypography
a Head Start
</h1>
<div class='kicker'>
<p>Below you’ll find some text marked up with the core elements of Type-a-file. View the source code to find out how to use them on your own site. This element, for example is called a “kicker.” It’s paragraph text that introduces the rest of the text. It’s useful for outlining your topic & looks killer. Just create a div with class=“kicker” and throw some paragraphs into it. Blammo!</p>
</div>
<h2>The Typographic Basics</h2>
<figure>
<img alt='placeholder image' src='http://dummyimage.com/480x248/ccc/fff' />
<figcaption>You’ll often want to caption photos. This is a .caption class</figcaption>
</figure>
<p><span class='drop-cap'>P</span>aragraphs are the core building block of typography online. You want to make sure you’ve got a good line-height and horizontal width—aka measure—for good readability. If you stack your lines too close together, or too far apart, lines become harder to read. Like a staircase where the steps are too shallow or too steep. The standard line-height online is something between 1.5 and 2.0 ems.
<a class='superscript' href='#ems'>1</a>
If your lines stretch too far across the page reading can feel like a tedious marathon. The standard single-column width online is about 70-90 characters.
</p>
<aside class='sidenote'>
<h4>This is a “sidenote”</h4>
<p>
It’s different than a sidebar because its content are directly related to the main content at left. When
<abbr>html5</abbr>
is more prevalent, you’ll be able to start using
<code>&lt;aside&gt;</code>
instead of a div with a class of .sidebar.
</p>
<p>I’ve set it up here as a div which contains h1s for titles, as well as paragraphs.</p>
</aside>
<p>If you look at the source code you’ll notice how the .sidenote to the right was written before this paragraph, which it is supposed to directly relate to. You’ll probably want to set up your asides in the same manner.</p>
<p>
These are the simple beginnings of Type-a-file. We’ve put in a lot of work to make good typography easier for you. Colors & structure we leave to you, but typographically, we got you covered. Download the file and follow the instructions for installing and setting it up. Now we’ll get into some of the
<em>fancier</em>
elements we’ve built into Type-a-file.
</p>
<h2>Puttin’ on the Ritz</h2>
<p>
<span class='run-in'>Sometimes you want an opening phrase to pop.</span>
You could just put it in bold tags, but wouldn’t you rather use semantic markup?
<a class='superscript' href='#semantics'>2</a>
We’ve created a class called .run-in so that you can! Best practices claim you’ll usually want to keep those run-ins to one line.
</p>
<aside class='sidenote'>
<h4>Another sidenote.</h4>
<p>I thought it might be interesting to show you that you can put lists into sidenotes:</p>
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li>
<li>Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam</li>
</ul>
</aside>
<p>
Typically you want a nice, steady vertical rhythm to your page. Of course, some folks don’t
<span class='pullquote'>Speaking of intelligently deviating…</span>think
that it’s actually necessary on the web to stick to a baseline grid, but it can be a great guide from which you can intelligently deviate. Speaking of intelligently deviating, there are some key elements that make great deviations from the monotony of paragraphs: the “quotes.” These include blockquotes and a special Type-a-file class named “pullquote.” The latter is above, the former below:
</p>
<blockquote>
<p>Headings, subheads, block quotations, footnotes, illustrations, captions and other intrusions into the text create syncopations and variations against the base rhythm of regularly leaded lines. These variations can and should add life to the page, but the main text should also return after each variation precisely on beat and in phase.</p>
</blockquote>
<cite>Robert Bringhurst</cite>
<h2>Delineate, Demonstrate, Define</h2>
<p>This Type-a-file would of course be incomplete without specifications for lists, codes & definitions. It’s fairly common to indent both blockquotes and list elements, but seriously consider left aligning your text for these items and outdenting their bullets & other visual demarcations. It can present a cleaner appearance while also drawing focused attention to information points.</p>
<ol>
<li>This is a list that is well ordered.</li>
<li>It starts with one and goes to two.</li>
<li>Then it has a third item.</li>
<li>Followed by the fourth, and—in this case—last item.</li>
</ol>
<ul class="footnote">
<li>Un-ordered lists are just as simple.</li>
<li>The only difference being that the items are marks by bullets instead of numbers.</li>
<li>Don’t forget that lists can have list titles.</li>
<li>Finally we’ve reached the last un-ordered item.</li>
</ul>
<p>
If you’re a blogger geek, sooner or later you’ll want to tell everybody about some ripping
<abbr>css</abbr>
coding you concocted by posting it on your blog-o-tubes. So we’ve got you covered.
</p>
<pre><code>#header h1 a {&#x000A; display: block;&#x000A; width: 300px;&#x000A; height: 80px;&#x000A; } %p Then, since you’re an uber-geek-dufus-man-child who’s fascinated by proving to the world you have sooooo much knowledge to share, you’ll probably want to post some definitions or definition-like information where a title element is closely linked with a description of some kind. We got ya.</code></pre>
<dl>
<dt>Type-a-file</dt>
<dd>A really awesome way to get your site up to typographic snuff. It uses traditional semantic HTML tags along with some additional semantic classes named after commonly occurring elements in print design to create a solid typographic toolkit for your website, whoever you are.</dd>
<dt>CSS</dt>
<dd>CSS stands for Cascading Style Sheet. This is a document format which provides a set of style rules which can then be incorporated in an XHTML or HTML document. It is a means to separate web content from formatting and presentation information. CSS is also a Brazilian rock band from São Paulo. The band was labeled as part of the explosion of the New Rave scene. Their songs are in both English and Portuguese. CSS is an abbreviation for Cansei de Ser Sexy , literally “tired of being sexy” in Portuguese.</dd>
</dl>
<p>
You see how that works? You need something done typographically, Type-a-file does it. That simple. Now what are you waiting for? Find a flavor that suits your mood and go to town. Download the zip file. All the directions and files you’ll need will be squished inside. Oh, and when you’ve become a master
<abbr>css</abbr>er
and start making your own flavors of Type-a-file, come back and share them with the Type-a-file community!
</p>
<small>
This is just a
<code>small</code>
element. It’s really useful when you want to add a small note or bit of text to something that’s perhaps less important or a clarification of something. Another option in an arsenal of options.
</small>
<ol class='footnote'>
<li id='ems'>
<span class='run-in'>All about ems:</span>
An em is a unit of measurement in the field of typography. This unit defines the proportion of the letter width and height with respect to the point size of the current font. Originally the unit was derived from the width of the capital “M” in the currently used typeface. This unit is not defined in terms of any specific typeface, and thus is the same for all fonts at a given point size. So, 1 em in a 16 point typeface is 16 points
</li>
<li id='semantics'>
<span class='run-in'>Semantic Web:</span>
A group of methods and technologies to allow machines to understand the meaning—or “semantics”—of information on the World Wide Web. The term was coined by World Wide Web Consortium (W3C) director Tim Berners-Lee. According to the original vision, the availability of machine-readable metadata would enable automated agents and other software to access the Web more intelligently. The agents would be able to perform tasks automatically and locate related information on behalf of the user.
</li>
</ol>
<ol class="badges">
<li class="clean-start ">clean-start </li>
<li class="code-viewer ">code-viewer </li>
<li class="color ">color </li>
<li class="drupal-ui-patterns ">drupal-ui-patterns </li>
<li class="fonts ">fonts </li>
<li class="html5 ">html5 </li>
<li class="jquery-plugins ">jquery-plugins </li>
<li class="sass-mixins ">sass-mixins </li>
<li class="step-by-step ">step-by-step </li>
<li class="ui-patterns ">ui-patterns </li>
</ol>
</article>
</div>
<footer><div id='credit'>This markup is from the <a href='http://type-a-file.com'>Type-a-File</a> project. <div class='commons'>Type-a-file is a <a href='http://www.strangenative.com' target='_blank'>StrangeNative</a> product licensed under <a class='cc' href='http://www.creativecommons.com'> creative commons.</a> You're free to use it commercially or non-commercially. Just keep that credit line in there!</div></div></footer>
</div>
<!--
Javascript at the bottom for fast page loading
Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if necessary
-->
<script src='//ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.js'></script>
<script type='text/javascript'>
//<![CDATA[
window.jQuery || document.write("<script src='js/libs/jquery-1.6.min.js'>\x3C/script>")
//]]>
</script>
<script src='/js/libs/plugins.js?v=1'></script>
<script src='/js/script.js?v=1'></script>
<script src='/js/libs/320-up/helper.js?v=1'></script>
<script src='/js/kit/kit-source.jquery.js?v=1'></script>
<!--[if (lt IE 9) & (!IEMobile)]>
<script src="/js/libs/imgsizer.js"></script>
<![endif]-->
<script type='text/javascript'>
//<![CDATA[
// iOS scale bug fix
MBP.scaleFix();
// Respond.js
yepnope({
test : Modernizr.mq('(only all)'),
nope : ['/js/libs/respond.min.js']
});
//]]>
</script>
<!-- asynchronous google analytics: mathiasbynens.be/notes/async-analytics-snippet -->
<!-- change the UA-XXXXX-X to be your site's ID -->
<script type='text/javascript'>
//<![CDATA[
var _gaq=[["_setAccount","UA-XXXXX-X"],["_trackPageview"],["_trackPageLoadTime"]];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1;
g.src=("https:"==location.protocol?"//ssl":"//www")+".google-analytics.com/ga.js";
s.parentNode.insertBefore(g,s)}(document,"script"));
//]]>
</script>
</body>
</html>
/* SITE-WIDE DESIGN -------------------------------------------------------------- */
body {
background: #e6e6e6;
color: #1a1a1a;
font-family: sans-serif;
font-size: 16px;
line-height: 1.5;
}
article h1, article h2 {
font-family: Georgia, serif;
font-weight: bold;
}
article h1 {
color: #bada55;
}
article h2 {
color: #a2c72b;
}
.kicker, blockquote {
font-size: 19.2px;
line-height: 1.3;
}
@media screen and (min-width: 500px) {
figure {
max-width: 50%;
float: right;
}
}
figure img {
max-width: 100%;
}
figure figcaption {
background: rgba(186, 218, 85, 0.5);
}
.sidenote {
border: 1px solid #55d0da;
padding: 0 0.5em;
margin-bottom: 1em;
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
-ms-border-radius: 8px;
-o-border-radius: 8px;
border-radius: 8px;
-webkit-box-shadow: rgba(255, 255, 255, 0.8) 0 0 12px 6px;
-moz-box-shadow: rgba(255, 255, 255, 0.8) 0 0 12px 6px;
box-shadow: rgba(255, 255, 255, 0.8) 0 0 12px 6px;
clear: both;
}
@media screen and (min-width: 500px) {
.sidenote {
width: 50%;
clear: both;
float: right;
margin-left: 1em;
}
}
.sidenote h4 {
color: #249ca5;
font-family: sans-serif;
font-weight: bold;
text-shadow: white 1px 1px 1px;
}
.sidenote ol, .sidenote ul {
margin-left: 0;
padding-left: 1em;
}
blockquote {
border-left: 4px solid #a2c72b;
padding-left: 0.25em;
}
ol, ul {
margin-left: 1em;
}
ol.footnote, ul.footnote {
font-family: Georgia, serif;
font-style: italic;
font-size: 12.8px;
}
.logo {
text-indent: 110%;
white-space: nowrap;
overflow: hidden;
background-image: url('../images/logo.png?1334764305');
background-repeat: no-repeat;
background-position: 50% 50%;
width: 52px;
height: 32px;
}
.badges-sprite, .badges .clean-start, .badges .code-viewer, .badges .color, .badges .drupal-ui-patterns, .badges .fonts, .badges .html5, .badges .jquery-plugins, .badges .sass-mixins, .badges .step-by-step, .badges .ui-patterns {
background: url('../images/badges-s0ff3c45bab.png') no-repeat;
}
.badges {
margin: 0;
padding: 0;
border: 0;
overflow: hidden;
*zoom: 1;
text-indent: 110%;
white-space: nowrap;
overflow: hidden;
}
.badges li {
list-style-image: none;
list-style-type: none;
margin-left: 0;
white-space: nowrap;
display: inline;
float: left;
padding-left: 4px;
padding-right: 4px;
}
.badges li:first-child, .badges li.first {
padding-left: 0;
}
.badges li:last-child {
padding-right: 0;
}
.badges li.last {
padding-right: 0;
}
.badges .clean-start {
background-position: 0 -575px;
height: 115px;
width: 115px;
}
.badges .code-viewer {
background-position: 0 -805px;
height: 115px;
width: 115px;
}
.badges .color {
background-position: 0 0;
height: 115px;
width: 115px;
}
.badges .drupal-ui-patterns {
background-position: 0 -115px;
height: 115px;
width: 115px;
}
.badges .fonts {
background-position: 0 -1035px;
height: 115px;
width: 115px;
}
.badges .html5 {
background-position: 0 -345px;
height: 115px;
width: 115px;
}
.badges .jquery-plugins {
background-position: 0 -690px;
height: 115px;
width: 115px;
}
.badges .sass-mixins {
background-position: 0 -920px;
height: 115px;
width: 115px;
}
.badges .step-by-step {
background-position: 0 -460px;
height: 115px;
width: 115px;
}
.badges .ui-patterns {
background-position: 0 -230px;
height: 115px;
width: 115px;
}
// Create the design for your site below
/* SITE-WIDE DESIGN -------------------------------------------------------------- */
// VARIABLES
$badass: #bada55;
$darkgray: scale-color(black, $lightness: 10%);
$lightgray: scale-color(white, $lightness: -10%);
$badass-dark: scale-color($badass, $lightness: -20%);
$badass-trans: rgba($badass, 0.5);
$badass-derived: adjust-hue($badass, 110deg);
// $badass-trans: rgba($badass, 0.5);
$font-sans: sans-serif;
$font-serifs: Georgia, serif;
$font-size: 16px;
////////////////////////////
// STYLES
////////////////////////////
body {
background: $lightgray;
// inline color functions
// background: adjust-color($badass, $lightness: -20%, $alpha: -0.5);
color: $darkgray;
font-family: $font-sans;
font-size: $font-size;
line-height: 1.5;
// css3 mixin (compass)
// @include background-image(linear-gradient(left, $lightgray, $badass-trans));
}
////////////////////////////
// NESTING
////////////////////////////
article {
h1, h2 {
font-family: $font-serifs;
font-weight: bold;
}
h1 {
color: $badass;
}
h2 {
color: $badass-dark;
}
}
////////////////////////////
// MATH
////////////////////////////
.kicker {
font-size: $font-size * 1.2;
line-height: 1.3;
}
////////////////////////////
// @MEDIA BUBBLING
////////////////////////////
figure {
@media screen and (min-width: 500px) {
max-width: 50%;
float: right;
}
img {
max-width: 100%;
}
figcaption {
background: $badass-trans;
}
}
////////////////////////////
// MIXIN
////////////////////////////
@mixin float-aside($width: 33%) {
width: $width;
clear: both;
float: right;
margin-left: 1em;
}
////////////////////////////
// PUT IT TOGETHER
////////////////////////////
.sidenote {
border: 1px solid $badass-derived;
padding: 0 0.5em;
margin-bottom: 1em;
// css3 mixin (compass)
@include border-radius($font-size * 0.5);
// css3 mixin (compass)
// @include box-shadow(rgba($darkgray, 0.2) 0 6px 6px);
@include box-shadow(rgba($white, 0.8) 0 0 12px 6px);
clear: both;
// @media bubbling
@media screen and (min-width: 500px) {
@include float-aside(50%);
}
h4 {
color: darken($badass-derived, 20%);
font-family: $font-sans;
font-weight: bold;
// css3 mixin (compass)
@include text-shadow($white 1px 1px 1px);
}
ol, ul {
margin-left: 0;
padding-left: 1em;
}
}
////////////////////////////
// @EXTEND
////////////////////////////
blockquote {
@extend .kicker;
border-left: 4px solid $badass-dark;
padding-left: 0.25em;
}
////////////////////////////
// & REFERENCE
////////////////////////////
ol, ul {
margin-left: 1em;
&.footnote {
font-family: $font-serifs;
font-style: italic;
font-size: $font-size * 0.8;
}
}
////////////////////////////
// IMAGE REPLACEMENT
////////////////////////////
.logo {
@include replace-text-with-dimensions("logo.png");
}
////////////////////////////
// SPRITES AND LISTS
////////////////////////////
@import "badges/*.png";
$badges-sprite-dimensions: true;
// @include all-badges-sprites;
$badges: clean-start code-viewer color drupal-ui-patterns fonts html5 jquery-plugins sass-mixins step-by-step ui-patterns;
.badges {
@include horizontal-list;
@include hide-text;
@each $badge in $badges {
.#{$badge} {
// @extend .badges-#{$badge};
@include badges-sprite($badge);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment