I'm first-time using Compass spriting. I wanted to have icons images (all are in little different in sizes) centered position. like the attached image
I'm using this setting
$icons-spacing:40px;
@import "icons/*.png";
@include all-icons-sprites;
the css i'm getting is (for example)
.icons-adventure {
background-position: 0 -608px;
}
It's not that as I required. I want to give more spacing from top and left.
You may want to check out this Github Gist: https://gist.github.com/adamlogic/3577147, which has helped me fix spriting issues in the past and also gain a better understanding of how spriting in Compass works.
Of particular interest to you may be the portion where the author mentions the following: (pasted here in case the Gist is removed)
"I took this a bit further by defining my own (sprite) mixin."
$spritemap-spacing: 50px
@import "spritemap/*.png"
=background-sprite($name, $repeat: no-repeat, $offset-x: 0, $offset-y: 0)
background-image: $spritemap-sprites
background-repeat: $repeat
+sprite-background-position($spritemap-sprites, $name, $offset-x, $offset-y)
// if no offsets given, set the dimensions of the element to match the image
@if $offset-x == 0 and $offset-y == 0
+sprite-dimensions($spritemap-sprites, $name)
"and how I'm using it"
// simplest case; sets the background image and dimensions of the element
h3
+background-sprite(ribbonfull)
// custom offset; does not set the dimensions of the element
h2
+background-sprite(ribbonend, no-repeat, 3px, 22px)
// repeating backgrounds are possible, too
#positions
+background-sprite(doubleline, repeat-x, 0, 45px)
And, the author's generated CSS:
h3 {
background-image: url('/images/spritemap-sb826ca2aba.png');
background-repeat: no-repeat;
background-position: 0 -405px;
height: 29px;
width: 295px; }
h2 {
background-image: url('/images/spritemap-sb826ca2aba.png');
background-repeat: no-repeat;
background-position: 3px -296px; }
#positions {
background-image: url('/images/spritemap-sb826ca2aba.png');
background-repeat: repeat-x;
background-position: 0 -751px; }
I’ve found two workarounds for this issue, both not perfect:
@import "icons/*.png"; el { position: relative; } el:after { content: ""; position: absolute; left: 50%; top: 50%; @include icons-sprite(some_icon); margin-top: - round(icons-sprite-height(some_icon) / 2); margin-left: - round(icons-sprite-width(some_icon) / 2); }
$icons-spacing
defines the number of pixels that separates each image in the generated sprite map. I believe you want to adjust the $icons-position
which adjusts (offsets) the generated background-position
styles
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With