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 

Want me to help develop your next project or application?

Contact Us

Specializing in Ruby-on-Rails, Javascript, Multi-Platform Electron Desktop Apps and Hybrid Cordova Mobile Apps.

Recommended Posts