网页中多个图标在一张图片上,使用css将各图标显示

版权声明:转载请注明来源,http://blog.csdn.net/u010071211 https://blog.csdn.net/u010071211/article/details/81738280

test.png

完整的代码:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <style>
	    .tree-default{
                width:100px;
                height:100px;
                margin:50px;  /*为了查看的效果更明显*/
                border-radius: 10px;
                border:1px #e8e8e8 solid;
            }
            .tree-font{
                background: url("test.png") -200px -100px no-repeat;
            }
            .tree-time{
            	/*background-color: */
                background-image: url("test.png");
                background-repeat: no-repeat;
                background-position: -100px -150px;
                background-size:250px 200px;   /*整张图片都变小之后再计算偏移量*/
            }
        </style>
    </head>
    <body>
        <div class="tree-default tree-font"></div>
        <div class="tree-default tree-time"></div>
    </body>
</html>

完成后的效果:

猜你喜欢

转载自blog.csdn.net/u010071211/article/details/81738280