Html css

Responsive Background Image Sprites In CSS

Posted by Weston Ganger on March 15, 2016

Using sprites is pretty sweet I think. You will probably need to make it responsive at one point.

Heres how to do it using plain CSS.

<div class="sprite-container">
  <div class="sprite"></div>

  width: 400px;

  /* Create a Responsive Square */
  width: 100%;
  height: 0;
  padding-bottom: 100%;

  /* Set The Sprite as the Background */
  background-image: url("images/ourimage.png");
  background-position: 0 0;
  background-size: 200%; //number of images horizontally * 100

/* On Hover Show Second of Two Images */
  background-position: 100% 0;

Related External Links:

Posted in HTML / CSS and Tagged with sprites 

Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts