Skip to content

Sprites inside @media queries #617

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

Open
dbanck opened this issue Nov 15, 2011 · 7 comments
Open

Sprites inside @media queries #617

dbanck opened this issue Nov 15, 2011 · 7 comments
Assignees

Comments

@dbanck
Copy link

dbanck commented Nov 15, 2011

I'm using sprites inside a @media screen and (max-width: 480px) query.

But the generated CSS will apply to all elements and not only those inside the media-query. So it will override my other sprite.

Example:
main.sass:

body

  #main-navigation
    background: inherit

    .home-button
      +icons-sprite(navigation-home)

_mobile.sass:

@import sprites/mobile

@media screen and (max-width: 480px)
  body
    overflow: auto

    #main-navigation
      background: none

      .home-button
        +mobile-sprite(navigation-home)

The generated CSS looks like this:

.icons-sprite, body #main-navigation .home-button {
  background: url('/images/icons-sf5e32584e9.png') no-repeat;
}

.mobile-sprite, body #main-navigation .home-button {
  background: url('/images/mobile-s32b9a3f1df.png') no-repeat;
}

@media screen and (max-width: 480px) {
  body #main-navigation .home-button {
    background-position: 0 -116px;
  }
}

So the second sprite will override the first one, even if it's just indented for mobile usage.

@scottdavis
Copy link
Member

ho hum this is a bad bug @chriseppstein

@chriseppstein
Copy link
Member

It's not a bug. The mixins set up the per-sprite properties and then extend the base class. In order for this to work, you have to define the base class in the proper media context. This means that you can't use the magic import, but you can run

compass sprite --skip-overrides "path/to/sprites/*.png"

and then edit that file to meet your needs and import it instead.

Maybe we should add some docs for this?

@dbanck
Copy link
Author

dbanck commented Nov 16, 2011

If it's not a bug, some docs with examples would be really great. (:

@ghost ghost assigned chriseppstein Dec 1, 2011
@dunglas
Copy link

dunglas commented Mar 28, 2012

Do you have an exemple of Compass sprites inside of media queries?

@dfadler
Copy link

dfadler commented Jul 13, 2012

If anyone still needs a solution for using sprites within media queries I've created a mixin that will help you.
https://gist.github.com/3105369

@brubrant
Copy link

@dfadler Man, you just saved my day!!

@u-foka
Copy link

u-foka commented Jul 12, 2015

Another solution I've created to serve quality sprites for high dpi screens: https://gist.github.com/d009f35ca1bda8d71f52.git

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

No branches or pull requests

7 participants