Skip to content

Instantly share code, notes, and snippets.

@anderssvendal
Created June 11, 2012 10:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anderssvendal/2909454 to your computer and use it in GitHub Desktop.
Save anderssvendal/2909454 to your computer and use it in GitHub Desktop.
Simple retina backgrounds with sass
require 'sass_extensions'
module Sass::Script::Functions
def gsub(string, regexp, replacement)
Sass::Script::String.new(string.value.gsub(Regexp.new(regexp.value), replacement.value))
end
declare :gsub, args: [:string, :regexp, :replacement]
end
@mixin image-replacement
display: block
text-indent: -9999px
outline: none
@mixin bg($name, $left: left, $top: top, $repeat: no-repeat, $retina: true)
background-image: image-url($name)
background-position: $left $top
background-repeat: $repeat
@if $retina
$retina-name: gsub($name, "(.*)\.([a-zA-Z]+)", "\1@2x.\2")
@media only screen and (-webkit-min-device-pixel-ratio: 2)
background-image: image-url($retina-name)
background-size: image-width($name) image-height($name)
@mixin sheet($width, $height, $left, $top, $image-replacement: true)
@if $image-replacement
+image-replacement
width: $width
height: $height
+bg("spritesheet.png", $left, $top, no-repeat, true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment