Skip to content

Instantly share code, notes, and snippets.

@jasonkmccoy
Created February 18, 2015 20:26
Show Gist options
  • Save jasonkmccoy/02a37d296950169fd526 to your computer and use it in GitHub Desktop.
Save jasonkmccoy/02a37d296950169fd526 to your computer and use it in GitHub Desktop.
Sass Variables: Sass Bites Podcast #10
/* CSS Output */
/* Example #1 */
.blog {
color: #555;
background: tan;
width: 800px;
height: auto;
}
.blog__article {
font-size: 1.2rem;
padding: 20px;
}
.blog__article--link {
border-bottom: 1px dashed green;
font-size: 1.44rem;
color: maroon;
text-decoration: none;
}
.blog__article--link:hover {
color: white;
}
/* Example #2: Micah */
.widget-title {
padding: 0 2em;
}
.widget-picture {
padding-left: 1em;
}
<!-- HTML code -->
<div class="blog">
<article class="blog__article">
This is some text for a blog article. Here is a <a href="#" class="blog__article--link">link</a> for an image.
Blah blah blah blah blah. Blah blah blah blah blah blah blah. Blah blah blah blah blah blah. Blah blah blah.
</article>
</div>
/* Sass Code */
// @import a link to your variables in the future
// i.e. partials/_variables.sass
// instead of having your variables here
// Variables must start with a $
// You CAN overwrite variables
$primary-bg: tan
$primary-color: #555
$default-font-size: 1.2rem
$gutter: 20px
$blog-link: maroon
$blog-link-hover: white
$primary-border: 1px dashed green
/* Example #1 */
.blog
color: $primary-color
background: $primary-bg
width: 800px
height: auto
.blog__article
font-size: $default-font-size
padding: $gutter
.blog__article--link
border-bottom: $primary-border
font-size: $default-font-size * 1.2
color: $blog-link
text-decoration: none
&:hover
color: $blog-link-hover
/* Example #2: Micah */
$widget-padding: 2em
$widget-class: picture
$direction: left
.widget-title
padding: 0 $widget-padding
.widget-#{$widget-class}
padding-#{$direction}: $widget-padding/2
/* SCSS code */
// @import a link to your variables in the future
// i.e. partials/_variables.sass
// instead of having your variables here
// Variables must start with a $
// You CAN overwrite variables
$primary-bg: tan;
$primary-color: #555;
$default-font-size: 1.2rem;
$gutter: 20px;
$blog-link: maroon;
$blog-link-hover: white;
$primary-border: 1px dashed green;
/* Example #1 */
.blog {
color: $primary-color;
background: $primary-bg;
width: 800px;
height: auto;
}
.blog__article {
font-size: $default-font-size;
padding: $gutter;
}
.blog__article--link {
border-bottom: $primary-border;
font-size: $default-font-size * 1.2;
color: $blog-link;
text-decoration: none;
&:hover {
color: $blog-link-hover;
}
}
/* Example #2: Micah */
$widget-padding: 2em;
$widget-class: picture;
$direction: left;
.widget-title {
padding: 0 $widget-padding;
}
.widget-#{$widget-class} {
padding-#{$direction}: $widget-padding / 2;
}
@jasonkmccoy
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment