compass/doc-src/content/help/tutorials/spriting/magic-selectors.markdown

74 lines
1.9 KiB
Markdown
Raw Normal View History

2011-09-07 02:37:43 +00:00
---
title: Sprite Magic Selectors
layout: tutorial
crumb: Magic Selectors
classnames:
- tutorial
---
# Sprite Tutorial
2011-09-07 02:37:43 +00:00
<%= sprite_tutorial_links %>
## Magic Selectors
If you want to add selectors for your sprites, it's easy todo by adding `_active` `_target` or `_hover` to the file name, In the example below we have a sprite directory that looks like:
* `my-buttons/glossy.png`
* `my-buttons/glossy_hover.png`
* `my-buttons/glossy_active.png`
* `my-buttons/glossy_target.png`
2011-09-07 02:37:43 +00:00
Now in our sass file we add:
@import "my-buttons/*.png";
2011-09-07 02:37:43 +00:00
a {
@include my-buttons-sprite(glossy)
2011-09-07 02:37:43 +00:00
}
2011-09-07 02:37:43 +00:00
And your stylesheet will compile to:
.my-buttons-sprite, a {
background: url('/my-buttons-sedfef809e2.png') no-repeat;
2011-09-07 02:37:43 +00:00
}
a {
background-position: 0 0;
}
a:hover, a.glossy_hover, a.glossy-hover {
background-position: 0 -40px;
2011-09-07 02:37:43 +00:00
}
a:target, a.glossy_target, a.glossy-target {
background-position: 0 -60px;
2011-09-07 02:37:43 +00:00
}
a:active, a.glossy_active, a.glossy-active {
background-position: 0 -20;
2011-09-07 02:37:43 +00:00
}
Alternatively you can use the `@include all-my-buttons-sprites;` after the import and get the following output:
2011-09-07 02:37:43 +00:00
.my-buttons-sprite, .my-buttons-glossy {
background: url('/my-buttons-sedfef809e2.png') no-repeat;
2011-09-07 02:37:43 +00:00
}
.my-buttons-glossy {
2011-09-07 02:37:43 +00:00
background-position: 0 0;
}
.my-buttons-glossy:hover, .my-buttons-glossy.glossy_hover, .my-buttons-glossy.glossy-hover {
background-position: 0 -40px;
2011-09-07 02:37:43 +00:00
}
.my-buttons-glossy:target, .my-buttons-glossy.glossy_target, .my-buttons-glossy.glossy-target {
background-position: 0 -60px;
2011-09-07 02:37:43 +00:00
}
.my-buttons-glossy:active, .my-buttons-glossy.glossy_active, .my-buttons-glossy.glossy-active {
background-position: 0 -20px;
2011-09-07 02:37:43 +00:00
}
2011-09-07 02:37:43 +00:00
## Disabling
To disable this feature set `$disable-magic-sprite-selectors` to true before calling the sprite mixin
2011-09-07 02:37:43 +00:00
a {
2011-09-07 02:50:50 +00:00
$disable-magic-sprite-selectors:true;
@include my-buttons-sprite(glossy)
2011-09-07 02:37:43 +00:00
}