Skip to content

Instantly share code, notes, and snippets.

@azinazadi
Forked from chriseppstein/0_selector_hacks.scss
Created February 22, 2012 10:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save azinazadi/1884016 to your computer and use it in GitHub Desktop.
Save azinazadi/1884016 to your computer and use it in GitHub Desktop.
This gist demonstrates some uses of the new sass feature: Passing content blocks to mixins.
@mixin ie6 { * html & { @content } }
#logo {
background-image: url("/images/logo.png");
@include ie6 { background-image: url("/images/logo.gif"); }
}
=ie6
* html &
@content
#logo
background-image: url("/images/logo.png")
+ie6
background-image: url("/images/logo.gif")
#logo { background-image: url("/images/logo.png"); }
* html #logo { background-image: url("/images/logo.gif"); }
@mixin keyframes {
@-moz-keyframes { @content; }
@-webkit-keyframes { @content; }
}
@include keyframes {
0% { opacity: 0; }
100% { opacity: 1; }
}
=keyframes($name)
@-webkit-keyframes $name
@content
@-moz-keyframes $name
@content
@-ms-keyframes $name
@content
@-o-keyframes $name
@content
+keyframes(show)
0%
opacity: 0
100%
opacity: 1
//if the above didnt work, this is the workarround
@each $browser in -webkit-, -moz-, -ms-, -o-, ''
@#{$browser}keyframes shrink
from
#{$browser}transform: scale(1)
to
#{$browser}transform: scale(0.3)
@mixin respond-to($media) {
@if $media == handhelds {
@media only screen and (max-width: 479px) { @content; }
}
@else if $media == wide-handhelds {
@media only screen and (min-width: 480px) and (max-width: 767px) { @content; }
}
@else if $media == tablets {
@media only screen and (min-width: 768px) and (max-width: 959px) { @content; }
}
}
#sidebar {
float: left;
width: 300px;
@include respond-to(handhelds) { float: none; }
@include respond-to(wide-handhelds) { float: none; }
@include respond-to(tablets) { width: 240px; }
}
=respond-to($media)
@if $media == handhelds
@media only screen and (max-width: 479px)
@content
@else if $media == wide-handhelds
@media only screen and (min-width: 480px) and (max-width: 767px)
@content
@else if $media == tablets
@media only screen and (min-width: 768px) and (max-width: 959px)
@content
#sidebar
float: left
width: 300px
+respond-to(handhelds)
float: none
+respond-to(wide-handhelds)
float: none
+respond-to(tablets)
width: 240px
#sidebar { float: left; width: 300px; }
@media only screen and (max-width: 479px) { #sidebar { float: none; } }
@media only screen and (min-width: 480px) and (max-width: 767px) { #sidebar { float: none; } }
@media only screen and (min-width: 768px) and (max-width: 959px) { #sidebar { width: 240px; } }
//this will let you set lots of crossbrowser thingies without using compass or bourbon
=cross-browser($attr, $value)
-webkit-#{$attr}: $value
-moz-#{$attr}: $value
-ms-#{$attr}: $value
-o-#{$attr}: $value
#{$attr}: $value
//example
cross-browser(border-radius, 5px)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment