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

Problem

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?

http://dabblet.com/gist/2212456

HTML

...
...

CSS

/* begin button styles */

.switch-wrapper{
    width:400px;
    margin:220px;
}

.switcher {
    background:#507190;
    vertical-align: bottom;
    position: relative;
    display: inline-block;
    max-width: 100%;
    vertical-align: bottom;
    box-shadow: 1px 1px 1px rgba(0,0,0,.3);
}
#left{
    background-image: url(http://www.codedevelopr.com/assets/images/switcher.png);
    background-position: -0px -0px;
}


#right{
    background-image: url(http://www.codedevelopr.com/assets/images/switcher.png);
    background-position: -0px -17px;
}


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

}
.right{
    border-radius: 0 6px 6px 0;
    width: 45px; height: 38px;
    margin: 0 0 0 -6px

}

.switcher:hover,
.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

Solution

  1. Block & inline method

http://dabblet.com/gist/2213271

  1. Absolute method

http://dabblet.com/gist/2213121

Solution courtesy of: Praveen Vijayan

Discussion

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

×