http://slid.es/illepic/sass-at-content
If it has arguments, use a mixin.
Otherwise, extend that bad boy.
// an extendable class
.extendable-style {
font-weight: bold;
line-height: 1.7;
}
// apply
.thingy-1{ @extend .extendable-style; }
.child .of .something{ @extend .extendable-style; }
// output
.extendable-style,
.thingy-1,
.child .of .something{
font-weight: bold;
line-height: 1.7;
}
// mixin definition
@mixin mixin-demo($bgcolor, $textcolor){
background: $bgcolor;
text-color: $textcolor;
}
// application
.thingy-1{
@include mixin-demo(blue, green);
}
// output
.thingy-1 {
background: blue;
text-color: green;
}
// define mixin
@mixin content-example($color) {
background: $color;
@content;
}
// pass extra stuff to it
.my-selector {
@include content-example(blue) {
color: green; // this is extra "content" we're sending over
}
}
// output
.my-selector {
background: blue;
color: green;
}
Kind of cool. But not as ermagerd as:// ie6 star hack: "* html" works for ie6 only
@mixin ie6 { * html & { @content } // pay attention to the "&" } // apply #logo { background-image: url("/images/logo.png"); @include ie6 { background-image: url("/images/logo.gif"); } }
// output #logo { background-image: url("/images/logo.png"); } * html #logo { background-image: url("/images/logo.gif"); }
Two major tricks here:
Cooler still. But ...
.sidebar {
width: 300px;
@media screen and (orientation: landscape) {
width: 500px;
}
}
// output
.sidebar {
width: 300px;
}
@media screen and (orientation: landscape) {
.sidebar {
width: 500px;
}
}
SASS media query reference
Adapted from chrisepptein's gist@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;
} } } // apply #sidebar { float: left; width: 300px; @include respond-to(handhelds) { float: none; } @include respond-to(wide-handhelds) { float: none; } } // output #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; } }
@include respond-to(tablet-portrait) {
@include sprites-sprite("logo-for-tablets");
}
// setup code here
// apply normal and 2x versions of pngs to elements
.icon-target { @include retina-sprite-item('target', $sprites, $sprites2x); }
// see gist for detailed setup
@mixin icon-font($font-name) { @extend .icon-#{$font-name}; @extend %icon-font; &:before { @content; } } //to call the search icon @include icon-font(search) { padding-right: .5em; text-shadow: 1px 1px 2px (#000); }
"… we hashed out whether there were performance implications of combining vs scattering Media Queries and came to the conclusion that the difference, while ugly, is minimal at worst, essentially non-existent at best."
- Sam Richards (Snugug)