Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add margin option. #24

Closed
wants to merge 1 commit into from
Closed

Add margin option. #24

wants to merge 1 commit into from

Conversation

phallguy
Copy link

Instead of adjusting the size of individual sprites, the margin option simply increases the y/x offsets between each sprite, retaining the original image size.

Instead of adjusting the size of individual sprites, the margin option
simply increases the y/x offsets between each sprite, retaining the
original image size.
@jkphl
Copy link
Collaborator

jkphl commented Aug 11, 2014

Hi @phallguy,

first of all: thanks for your contribution!

Before I merge your PR, however, I would like to understand it's goals — which I don't so far. This might also result from the fact that you describe your changes using the term "sprite" in a somewhat misleading way (as long as sprite is defined as numerous small images or icons combined into a larger image). I suspect that your aim is what the padding option already accounts for, although one might find it's function somewhat counterintuitive. Did you try to achieve your goals by using padding before?

Cheers, Joschi

@phallguy
Copy link
Author

Yep, it's very similar to padding and serves the same basic purpose. But padding actually changes the width of the images that are composed to make the sprite. So in our scss/less when trying to calculate a target width for an image it's always off by some small amount because to the padding. And due to some bugs in Safari we can't have fractional heights in our target images so backing out the padding in the css won't work. Using the margin option, the original width of the source image is retained, while still adding spacing around the sprite so they don't bleed into each other.

This is a part of the generated template that we use

.chrome-svg( @height: 100 ) {
  @scale: @height / 100;
  background-size: floor( 405px * @scale), floor( 1000px * @scale );
  background-image: image-url('chrome-sprite.svg');
}

.chrome-app-menu( @height: 100 ) {
  .chrome-svg( @height );

  @scale: @height / 100;
  background-position: 0 floor( 0px * @scale );
  width: floor( 100px * @scale );
  height: floor( 100px * @scale );
}

I can then create a css class to create a 32px version of the icon and a 44px version of the icon from the same source image in the sprite.

.app-icon-32
{
  .chrome-app-menu( 32 );
}

.app-icon-44
{
 .chrome-app-menu( 44 );
}

@jkphl jkphl self-assigned this Dec 29, 2014
@jkphl
Copy link
Collaborator

jkphl commented Dec 29, 2014

Hi @phallguy,

I just published the next major release of svg-sprite. It's rewritten from scratch and has the padding option reworked — now supporting a spacing.box option that works similar to CSS's box-sizing. Could you please check if this suffices your needs? I'll close the issue for now, but please feel free to re-open it in case you've still got problems.

Cheers & a happy new year,
Joschi

@jkphl jkphl closed this Dec 29, 2014
@phallguy
Copy link
Author

phallguy commented Jan 5, 2015

Thanks for the hard work. I've just read the docs but so far this looks great.

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

Successfully merging this pull request may close these issues.

2 participants