File: magic-selectors.markdown

package info (click to toggle)
ruby-compass 0.12.2~dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 8,308 kB
  • sloc: ruby: 10,474; makefile: 42; xml: 14
file content (73 lines) | stat: -rw-r--r-- 1,991 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
---
title: Sprite Magic Selectors
layout: tutorial
crumb: Magic Selectors
classnames:
  - tutorial
---
# Sprite Tutorial
<%= 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`

Now in our sass file we add:

    @import "my-buttons/*.png";
    
    a {
      @include my-buttons-sprite(glossy)
    }

And your stylesheet will compile to:

    .my-buttons-sprite, a {
      background: url('/my-buttons-sedfef809e2.png') no-repeat;
    }

    a {
      background-position: 0 0;
    }
    a:hover, a.glossy_hover, a.glossy-hover {
      background-position: 0 -40px;
    }
    a:target, a.glossy_target, a.glossy-target {
      background-position: 0 -60px;
    }
    a:active, a.glossy_active, a.glossy-active {
      background-position: 0 -20;
    }

Alternatively you can use the `@include all-my-buttons-sprites;` after the import and get the following output:

    .my-buttons-sprite, .my-buttons-glossy {
      background: url('/my-buttons-sedfef809e2.png') no-repeat;
    }

    .my-buttons-glossy {
      background-position: 0 0;
    }
    .my-buttons-glossy:hover, .my-buttons-glossy.glossy_hover, .my-buttons-glossy.glossy-hover {
      background-position: 0 -40px;
    }
    .my-buttons-glossy:target, .my-buttons-glossy.glossy_target, .my-buttons-glossy.glossy-target {
      background-position: 0 -60px;
    }
    .my-buttons-glossy:active, .my-buttons-glossy.glossy_active, .my-buttons-glossy.glossy-active {
      background-position: 0 -20px;
    }

## Disabling

To disable this feature set `$disable-magic-sprite-selectors` to true before calling the sprite mixin

    a {
      $disable-magic-sprite-selectors:true;
      @include my-buttons-sprite(glossy)
    }