Skip to content

Instantly share code, notes, and snippets.

@Heintzsight
Created January 17, 2013 17:18
Show Gist options
  • Save Heintzsight/4557654 to your computer and use it in GitHub Desktop.
Save Heintzsight/4557654 to your computer and use it in GitHub Desktop.
A CodePen by Matt. Style tiles with SCSS - Design style tiles in the browser with SCSS! Fork this in CodePen and make your own tiles. Share your tiles with clients with the Full Page link. Go CodePen Pro and update styles on the fly in Live View in a meeting with your client. It's responsive, too. Get your in-browser design on. On GitHub at http…
<div class="header-wrapper">
<header class="group">
<h1>Style Tile<br>Template</h1>
<hgroup class="project-title">
<h2>Project name</h2>
<h3>Style tile</h3>
<h4>Version 1</h4>
</hgroup>
</header>
</div>
<div class="main grid">
<div class="graphic-samples col-1-2">
<section class="swatches group">
<h3 class="section-heading">Colour swatches</h3>
<ul class="swatchgrid group">
<li class="color-swatch-1 swatch-1-5"></li>
<li class="color-swatch-2 swatch-1-5"></li>
<li class="color-swatch-3 swatch-1-5"></li>
<li class="color-swatch-4 swatch-1-5"></li>
<li class="color-swatch-5 swatch-1-5"></li>
</ul>
</section>
<section class="textures">
<h3 class="section-heading">Textures</h3>
<ul class="swatchgrid group">
<li class="texture-swatch-1 swatch-1-3"></li>
<li class="texture-swatch-2 swatch-1-3"></li>
<li class="texture-swatch-3 swatch-1-3"></li>
</ul>
</section>
<section class="buttons">
<h3 class="section-heading">Buttons</h3>
<div>
<a href="#" class="button-1">Button 1</a>
<a href="#" class="button-2">Button 2</a>
</div>
</section>
</div>
<div class="typography-samples col-1-2">
<section class="typography-main">
<h3 class="typography-sample">A sample header</h3>
<p class="font-details-h3">
<span class="font-name">Font Name</span>,
<span class="font-color">#color value</span>
</p>
<h4 class="typography-sample">An example of a sub header</h4>
<p class="font-details-h4">
<span class="font-name">Font Name</span>,
<span class="font-color">#color value</span>
</p>
<p class="typography-sample">
This sample paragraph has <strong>strong parts</strong> and <em>emphasized parts</em>. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
</p>
<p class="font-details-p">
<span class="font-name">Font Name</span>,
<span class="font-color">#color value</span>
</p>
<a href="#" class="typography-sample">This is an example of a text link.</a>
<p class="font-details-a">
<span class="font-name">Font Name</span>,
<span class="font-color">#color value</span>
</p>
</section>
<section class="adjectives grid">
<h3 class="section-heading">Adjectives</h3>
<div class="grid group">
<p class="adjective-1 col-1-3">Lorem</p>
<p class="adjective-2 col-1-3">Ipsum</p>
<p class="adjective-3 col-1-3">Dolor</p>
</div>
<div class="grid group">
<p class="adjective-4 col-1-3">Magna</p>
<p class="adjective-5 col-1-3">Amet</p>
<p class="adjective-6 col-1-3">Sit</p>
</div>
</section>
</div>
</div>
<div class="footer-wrapper">
<footer class="group">
<small>
Style tile by Jerad Gallinger.<br>
<a href="http://jeradgallinger.ca">jeradgallinger.ca</a>
</small>
</footer>
</div>
/*
_____,-----------------------,_____
\ | STYLE TILES WITH SCSS | /
/____|-----------------------|____\
by Jerad Gallinger - jeradgallinger.ca
twitter.com/jeradg - codepen.io/jeradg
___________________________________
|,---------------------------------,|
|| +-------+ +-------+ +-------+ ||
|| +-------+ | | | | ||
|| | | | | ||
|| +-------+ +-------+ +-------+ ||
|| +-------+ +-------+ +-------+ ||
|| | | | \ | | | ||
|| | | | \ | | | ||
|| +-------+ +-------+ +-------+ ||
||_________________________________||
'-----------------------------------'
On GitHub:
github.com/jeradg/style-tiles-with-scss
--
Based on Samantha Warren's Style Tiles:
http://styletil.es/
http://www.alistapart.com/articles/style-tiles-and-how-they-work/
--
A brief explanation:
- Start at the top for the most basic options, and move down for more fine-grained styling.
- The SCSS is sectioned into (from top -> bottom):
- BASIC STYLING: main colors, basic typography, textures, and button styling.
- ADVANCED STYLING: Advanced options for the above items. If you want to make fancy buttons, do cool things with the texture boxes, or have fine-grained control over the typography samples and adjectives, do it here.
- SETTINGS
- Below the settings, everything comes together in the proper order to be compiled.
Play around! Use SCSS and Compass's colour functions to create colour schemes, try to do fancy stuff in the texture boxes, mess about with floats and margins to customize the layout -- make it your own.
And don't forget -- SAVE OFTEN!
*/
/* (And now for some JavaScript... let's hear it for progressive enhancement.)
*/
$( document ).ready( function() {
/* setHeight() keeps the swatches as squares by setting each swatch's height on document load, and updating it when the viewport is resized. */
var swatchGrids = $( ".swatchgrid" );
var setHeight = function( elements ) {
$( elements ).each( function() {
var firstChild = $( this ).find( ":first-child" );
$( this ).children().each( function() {
$( this ).height( $( firstChild ).width() );
});
});
};
setHeight( swatchGrids );
$( window ).resize( function() {
setHeight( swatchGrids );
});
/* updateFontDetails() changes the HTML of each .font-details-* on document load to reflect the styles of the immediately preceding .typography-sample. This allows you to update the styles of the typography samples on the fly without having to manually enter these details into the HTML. */
var updateFontDetails = function() {
$( ".typography-sample" ).each( function() {
var thisSample = $( this );
var getFontName = function( sample ) {
var splitFontStack = sample.css( "font-family" ).split( "," );
var justTheName = function() {
var rawFontName = splitFontStack[ 0 ]; //Get the first font-family from the font stack
if ( rawFontName.charAt( 0 ) == "\'" | "\"" ) {
return rawFontName.substring( 1, rawFontName.length - 1 ); //Remove the quotes from around the font-family name, if there are any
} else {
return rawFontName;
}
};
return justTheName();
};
var fontName = getFontName( thisSample );
var fontColor = thisSample.css( "color" );
var fontDetails = thisSample.next( "[class*=font-details-]" );
fontDetails.children( ".font-name" ).html( fontName );
fontDetails.children( ".font-color" ).html( fontColor );
});
};
updateFontDetails();
});
@import "compass";
/* Design style tiles in the browser with SCSS! Fork this in CodePen and make your own tiles. Share your tiles with clients with the Full Page link. Go CodePen Pro and update styles on the fly in Live View in a meeting with your client. It's responsive, too. Get your in-browser design on. (Documentation in the JS tab.) */
/* Web Fonts @import */
@import url(http://fonts.googleapis.com/css?family=Open+Sans:400italic,800italic,400,800);
@import url(http://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic,700italic);
/* BASIC STYLING
-------------------------------- */
/* Colours */
$color-1: rgb(159,28,25);
$color-2: rgb(101,209,251);
$color-3: rgb(5,171,235);
$color-4: rgb(255,133,0);
$color-5: rgb(255,36,31);
$header-background: $color-1;
$body-background: lighten($color-1, 90%);
$typography-samples-background: $body-background;
$footer-background: $body-background;
/* Basic typography */
$heading-font-family: 'Open Sans', sans-serif;
$heading-color: desaturate(darken($color-1, 15%), 80%);
$body-font-family: 'Droid Serif', serif;
$body-font-size: 1.6em;
$body-line-height: 1.5;
$body-color: #222;
$body-link-font-family: $heading-font-family;
$body-link-color: $color-3;
$header-color: white; /* font color in <header> */
/* Basic button styling */
$button-1-background-color: $color-3;
$button-1-border-radius: 4px;
$button-1-padding: 1em;
$button-2-background-color: $color-5;
$button-2-border-radius: $button-1-border-radius;
$button-2-padding: $button-1-padding;
/* Basic texture swatch styling */
$texture-swatch-1-background: url("http://subtlepatterns.subtlepatterns.netdna-cdn.com/patterns/pw_maze_white.png") top left repeat;
$texture-swatch-2-background: url("http://subtlepatterns.com/patterns/white_paperboard.png") top left repeat;
$texture-swatch-3-background: url("http://subtlepatterns.subtlepatterns.netdna-cdn.com/patterns/subtle_grunge.png") top left repeat;
/* end basic styling */
/* ADVANCED STYLING
-------------------------------- */
/* Main */
$main-background: $body-background;
$main-padding: 20px;
@mixin section-heading { /* e.g., h3's like "Possible colors", "Textures" */
font: italic 1.3em $heading-font-family;
color: #777;
margin-bottom: .5em;
}
/* Header */
$header-padding: $main-padding;
@mixin header-h1 {
//text-indent: -9999px; /*Uncomment this line if you're replacing the text with a logo. */
font: bold 3em/1 $heading-font-family;
color: $header-color;
text-transform: uppercase;
letter-spacing: -2px;
padding-right: .75em;
}
@mixin header-h2 {
font: bold 1.6em $heading-font-family;
color: rgba($header-color, .95);
}
@mixin header-h3 {
font: italic 1.2em $heading-font-family;
color: rgba($header-color, .95);
}
@mixin header-h4 {
font: .8em $body-font-family;
color: rgba($header-color, .95);
}
/* Colour swatches */
$color-swatch-1: $color-1;
$color-swatch-2: $color-2;
$color-swatch-3: $color-3;
$color-swatch-4: $color-4;
$color-swatch-5: $color-5;
$color-swatch-height: 5em;
/* Texture swatches */
@mixin texture-swatch-1 {
background: $texture-swatch-1-background;
}
@mixin texture-swatch-2 {
background: $texture-swatch-2-background;
}
@mixin texture-swatch-3 {
background: $texture-swatch-3-background;
}
$texture-swatch-height: 8em;
/* Buttons */
@mixin button-1 {
padding: $button-1-padding;
border-radius: $button-1-border-radius;
background: $button-1-background-color;
text-align: center;
text-decoration: none;
font: bold 1.25em/1 $heading-font-family;
letter-spacing: 1px;
color: lighten($button-1-background-color, 60%);
text-transform: uppercase;
text-shadow: 0px -1px 0px darken($button-1-background-color, 15%);
transition: all .2s ease;
&:hover {
background: darken($button-1-background-color, 15%);
}
}
@mixin button-2 {
padding: $button-2-padding;
border-radius: $button-2-border-radius;
background: $button-2-background-color;
text-align: center;
text-decoration: none;
font: bold 1.25em/1 $heading-font-family;
letter-spacing: 1px;
color: lighten($button-2-background-color, 60%);
text-transform: uppercase;
text-shadow: 0px -1px 0px darken($button-2-background-color, 15%);
transition: all .2s ease;
&:hover {
background: darken($button-2-background-color, 15%);
}
}
/* Typography samples */
@mixin typography-sample-h3 {
font: bold 2.4em/1.25 $heading-font-family;
margin-bottom: .25em;
color: $heading-color;
}
@mixin typography-sample-h4 {
font: italic 1.5em/1.25 $body-font-family;
margin-bottom: .25em;
color: $heading-color;
}
@mixin typography-sample-p {
font: 1em/1.5 $body-font-family;
color: $body-color;
strong {
font-weight: bold;
}
em {
font-style: italic;
}
}
@mixin typography-sample-a {
font: bold 1em $body-link-font-family;
color: $body-link-color;
text-decoration: none;
&:hover {
color: darken(saturate($body-link-color, 50%), 10%);
transition: all .3s ease;
}
}
@mixin typography-samples {
background: $typography-samples-background;
padding: 0;
@media (min-width: 50em) {
padding: 20px;
}
}
/* Adjectives */
@mixin adjective-1 {
font: italic 1.6em/1 $heading-font-family;
color: $color-1;
}
@mixin adjective-2 {
font: bold 1.25em/1.25 $body-font-family;
color: $color-3;
}
@mixin adjective-3 {
font: 1.5em/1 $heading-font-family;
color: $color-4;
}
@mixin adjective-4 {
font: 1.6em/1.15 $heading-font-family;
color: $color-2;
}
@mixin adjective-5 {
font: bold italic 3em/.7 $heading-font-family;
color: $color-5;
}
@mixin adjective-6 {
font: bold italic 1.8em/1.1 $body-font-family;
color: $color-3;
}
/* Footer */
$footer-padding: $main-padding;
$footer-background: $footer-background;
$footer-color: white;
@mixin footer {
padding: $footer-padding;
font: italic 1em/1.5 $heading-font-family;
color: $body-color;
a {
font-weight: bold;
color: $color-3;
text-decoration: none;
}
}
/* end advanced styling */
/* SETTINGS
-------------------------------- */
/* Typography samples settings */
$font-details-font: .75em/1 $body-font-family;
@mixin font-details {
margin-top: .5em;
margin-bottom: 2em;
font: $font-details-font;
color: lighten($body-color, 30%);
.font-color {
font-style: italic;
}
}
/* Grid settings */
$grid-padding: 30px;
/* Swatch grid settings (for the boxes containing Possible Colors and Textures */
$swatch-border: 4px solid white;
$swatch-shadow: 0px 0px 6px 0px rgba(0,0,0,.25);
$swatch-margin: 2%;
/* end settings */
/* ================================================== */
/* Clearfix
-------------------- */
.group:after {
visibility: hidden;
display: block;
content: "";
clear: both;
height: 0;
}
* html .group { zoom: 1; } /* IE6 */
*:first-child+html .group { zoom: 1; } /* IE7 */
/* General styling
-------------------- */
*, *:after, *:before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
html {
font-size: 62.5%;
}
body {
background: $body-background;
font: $body-font-size $body-font-family;
line-height: $body-line-height;
}
header, .main, footer {
max-width: 81em;
margin: 0 auto;
}
/* Header
-------------------- */
.header-wrapper {
background: $header-background;
}
header {
padding: $header-padding;
background: $header-background;
}
header h1, header hgroup {
position: relative;
float: left;
}
header h1 {
@include header-h1;
}
header h2 {
@include header-h2;
}
header h3 {
@include header-h3;
}
header h4 {
@include header-h4;
}
.project-title {
position: relative;
float: left;
}
/* Main
-------------------- */
.main {
padding: $main-padding;
background: $main-background;
}
.section-heading {
@include section-heading;
}
.main p {
margin-bottom: .5em;
}
section {
margin-bottom: 2em;
}
/* Swatches
-------------------- */
[class*="swatch-"] {
height: $color-swatch-height;
border: $swatch-border;
box-shadow: $swatch-shadow;
}
.color-swatch-1 {
background: $color-swatch-1;
}
.color-swatch-2 {
background: $color-swatch-2;
}
.color-swatch-3 {
background: $color-swatch-3;
}
.color-swatch-4 {
background: $color-swatch-4;
}
.color-swatch-5 {
background: $color-swatch-5;
}
/* Texture swatches
-------------------- */
[class*="texture-swatch-"] {
overflow: hidden;
height: $texture-swatch-height;
border: $swatch-border;
box-shadow: $swatch-shadow;
}
.texture-swatch-1 {
@include texture-swatch-1;
}
.texture-swatch-2 {
@include texture-swatch-2;
}
.texture-swatch-3 {
@include texture-swatch-3;
}
/* Buttons
--------------------- */
[class*="button-"] {
display: inline-block;
position: relative;
margin-right: 1em;
margin-bottom: 1em;
}
.button-1 {
@include button-1
}
.button-2 {
@include button-2
}
/* Typography samples
--------------------- */
.typography-samples {
@include typography-samples
}
h3.typography-sample {
@include typography-sample-h3;
}
h4.typography-sample {
@include typography-sample-h4;
}
p.typography-sample {
@include typography-sample-p;
}
a.typography-sample {
@include typography-sample-a;
}
p[class*="font-details-"] {
@include font-details;
}
/* Adjectives
-------------------- */
.adjective-1 {
@include adjective-1;
}
.adjective-2 {
@include adjective-2;
}
.adjective-3 {
@include adjective-3;
}
.adjective-4 {
@include adjective-4;
}
.adjective-5 {
@include adjective-5;
}
.adjective-6 {
@include adjective-6;
}
/* Footer
-------------------- */
.footer-wrapper {
background: $footer-background;
}
footer {
@include footer;
}
/* Grids
based on Chris Coyier's Dont Overthink It Grids
http://css-tricks.com/dont-overthink-it-grids/
-------------------- */
[class*='col-'] { float: left; }
.grid:after {
content: "";
display: table;
clear: both;
}
.col-1-2 {
width: 100%; /* Single-column by default, i.e., on mobile */
@media ( min-width: 50em ) { /* 2-column if viewport is wide enough*/
width: 50%;
}
}
.col-1-3 {
width: 100%;
@media ( min-width: 50em ) {
width: 33.3333%;
}
}
[class*="col-"] {
padding: 0;
@media ( min-width: 50em ) {
padding-left: $grid-padding;
}
}
[class*="col-"]:first-child { padding-left: 0; }
/* Swatch grids
[Want to add more swatch grid column options?
Formula for calculating swatch width:
width: (100% - ($swatch-margin * (y - 1))) / y;
where y = number of swatches in a grid row]
*/
[class*='swatch-'] { float: left; }
.swatchgrid:after {
content: "";
display: table;
clear: both;
}
.swatch-1-2 {
width: ( 100% - ( $swatch-margin * ( 1 ) ) ) / 2;
}
.swatch-1-3 {
width: ( 100% - ( $swatch-margin * ( 2 ) ) ) / 3;
}
.swatch-1-4 {
width: ( 100% - ( $swatch-margin * ( 3 ) ) ) / 4;
}
.swatch-1-5 {
width: ( 100% - ( $swatch-margin * ( 4 ) ) ) / 5;
}
[class*="swatch-"] { margin-left: $swatch-margin; }
[class*="swatch-"]:first-child { margin-left: 0; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment