Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Position Image Sprite with CSS on a button

Position Image Sprite with CSS on a button


I am trying to do something like this image below with CSS to build the buttons and then an image Sprite to show the center content of the button.

Here is a demo of the code I have so far, I am having trouble getting my sprite images to position correctly. Any help to improve this CSS to look more like my image above would be great. I think the actual HTML structure could be improved as well?




/* begin button styles */


.switcher {
    vertical-align: bottom;
    position: relative;
    display: inline-block;
    max-width: 100%;
    vertical-align: bottom;
    box-shadow: 1px 1px 1px rgba(0,0,0,.3);
    background-image: url(;
    background-position: -0px -0px;

    background-image: url(;
    background-position: -0px -17px;

    border-radius: 6px 0px 0px 6px;
    width: 45px; height: 38px;

    border-radius: 0 6px 6px 0;
    width: 45px; height: 38px;
    margin: 0 0 0 -6px


.selected {
    background: #27394b;
    box-shadow: -1px 1px 0px rgba(255,255,255,.4),
     inset 0 4px 5px rgba(0,0,0,.6),
      inset 0 1px 2px rgba(0,0,0,.6);

.switcher::after {
    content: ' ';
    width: 100%;
    height: 100%;
    position: absolute;
    top: -1px;
    left: -1px;
    border: solid 0px #1B1B1B;
    border-radius: 6px;

Problem courtesy of: JasonDavis


  1. Block & inline method

  1. Absolute method

Solution courtesy of: Praveen Vijayan


View additional discussion.

This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

Position Image Sprite with CSS on a button


Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription