As an example for mixins; Let's say you have a sprite with icons in a fixed grid. The icons are 32x32px each and you want to generate icons based on that sprite for both 32x32px and 16x16px. That's where a mixin can be quite handy.
@mixin icon($name, $left, $top)
{
&.#{$name}-16:not(.raw)
{
&:before
{
float: left;
content: "";
width: 16px;
height: 16px;
margin-right: 8px;
background-size: 300px 300px;
background-image: image_url('icons/sprite_gray.png');
background-position: -#{$left * 16}px -#{$top * 16}px;
}
&:hover:before { background-position: -#{$left * 16}px -#{$top * 16 + 16 * 1}px; }
&.active:before { background-position: -#{$left * 16}px -#{$top * 16 + 16 * 2}px; }
&.active.contrast:before { background-position: -#{$left * 16}px -#{$top * 16 + 16 * 3}px; }
}
&.#{$name}-16.raw
{
width: 16px;
height: 16px;
background-size: 300px 300px;
background-image: image_url('icons/sprite_gray.png');
background-position: -#{$left * 16}px -#{$top * 16}px;
}
&.#{$name}-32:not(.raw)
{
&:before
{
content: "";
width: 32px;
height: 32px;
background-size: 600px 600px;
background-image: image_url('icons/sprite_gray.png');
background-position: -#{$left * 32}px -#{$top * 32}px;
}
&:hover:before { background-position: -#{$left * 32}px -#{$top * 32 + 32 * 1}px; }
&.active:before { background-position: -#{$left * 32}px -#{$top * 32 + 32 * 2}px; }
&.active.contrast:before { background-position: -#{$left * 32}px -#{$top * 32 + 32 * 3}px; }
}
&.#{$name}-32.raw
{
display: inline-block;
width: 32px;
height: 32px;
background-size: 600px 600px;
background-image: image_url('icons/sprite_gray.png');
background-position: -#{$left * 32}px -#{$top * 32}px;
}
}
So with this mixin, I can give a name and the position of the icon to create styles, like:
.icon {
@include icon(user, 1, 1);
@include icon(role, 5, 1);
}
which gives me user-16, user-32, role-16, role-32
classes to implement icons.
(In this example, they are appended as :before
content, unless you use .raw
)