How to make a single image, treated as three different images?

后端 未结 3 899
逝去的感伤
逝去的感伤 2021-01-25 00:38

I was just going through a website code, and I saw an image for Social Networks link

\"enter

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-25 01:29

    You can set the background image position and crop it by setting width/height in the css file.

    //HTML

    
    

    //CSS

    .facebook{
        background:url(http://i.stack.imgur.com/LNPd7.png) 0px 0px no-repeat;
        width:30px;
        height:30px;
    }
    .facebook:hover{
        background:url(http://i.stack.imgur.com/LNPd7.png) 0px -30px no-repeat;
    }
    
    .twitter{
        background:url(http://i.stack.imgur.com/LNPd7.png) -30px 0px no-repeat;
        width:30px;
        height:30px;
    }
    .twitter:hover{
        background:url(http://i.stack.imgur.com/LNPd7.png) -30px -30px no-repeat;
    }
    
    .linkedin{
        background:url(http://i.stack.imgur.com/LNPd7.png) -60px 0px no-repeat;
        width:30px;
        height:30px;
    }
    .linkedin:hover{
        background:url(http://i.stack.imgur.com/LNPd7.png) -60px -30px no-repeat;
    }
    

    Here is the working example http://jsfiddle.net/kayadiker/uuKzQ/

提交回复
热议问题