Skip to content

Instantly share code, notes, and snippets.

@cbfrance
Created August 4, 2011 23:05
Show Gist options
  • Save cbfrance/1126530 to your computer and use it in GitHub Desktop.
Save cbfrance/1126530 to your computer and use it in GitHub Desktop.
I love how you can do stuff like this in Compass/Sass with mixins — for styling similar but different elements
@mixin resource-layout(
$width: $primary_width,
$language_dir: left,
$type: discussion,
$background_color: none,
$icon_width: 40px,
$padding: $default_padding) {
background-color: $background_color;
border-top: 2px solid lighten($tarawera, 10%);
float: $language_dir;
width: $width;
margin-#{opposite-position($language-dir)}: $padding;
padding: 5px 0;
position: relative;
overflow: hidden;
height: 250px;
h3 {
padding: 0;
padding-#{$language_dir}: $icon_width;
max-height: 125px;
overflow: hidden;
font-size: 1.3em;
}
object {
margin: $padding;
}
div.type-icon {
width: $icon_width;
position: absolute;
padding-top: 7px;
#{$language_dir}: 0;
}
div.inner-wrap {
ul.links{
float: $language_dir;
margin-top:$padding/2;
li {
padding:0;
a.comment-responses {
background:url('../images/response-icon.png') no-repeat center $language_dir;
padding-#{$language_dir}: $padding*2;
color: $alto;
}
}
li.node_read_more {
margin-#{$language_dir}:$padding*2;
}
}
}
@if $type == "pdf" {
border-top-color: $pdf_red!important;
} @else if $type == "word" {
border-top-color: $ms_word_blue!important;
} @else if $type == "link" {
border-top-color: $link_grey!important;
} @else if $type == "slides" {
border-top-color: $slides_orange!important;
} @else if $type == "discussion" {
border-top-color: $link_grey!important;
height: 200px;
} @else if $type == "video" {
border-top-color: $video_black!important;
height: 300px;
position: relative;
.type-icon { display: none; }
h3 {padding: 0!important; margin: 0;}
a.comment-responses {
position: absolute;
bottom: 10px;
}
}
}
@cbfrance
Copy link
Author

cbfrance commented Aug 4, 2011

This would be implemented with a selector like this:
.teaser-pdf { @include resource-layout(20%, $direction, pdf); }
.teaser-video { @include resource-layout(30%, $direction, video); }

(You would have to be in some context where your $direction was set based on using an RTL language or not.)

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