首页 > 代码库 > CSS精灵写法

CSS精灵写法

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
.div1{ width:420px;}
.div1 li { list-style: none; float:left; border:1px solid #EAF3FA; background:#FBFCFF; margin:10px; width:120px; height:40px; line-height:40px; padding-left:10px;}
.div span{padding-left:25px;/*空出16px来显示图标*/
          height: 35px; /*设定好高度,让超出部分不可见*/
          background:url(888888.png) no-repeat;/*所有的li共享一张图片*/}
.a{ background-position:-19px -22px; width:25px; height:20px;}
.b{ background-position:-146px -22px;width:25px; height:20px;}
.c{ background-position:-19px -68px;width:25px; height:25px;}
.d{ background-position:-146px -70px;width:25px; height:25px;}
.e{ background-position:-21px -120px;width:25px; height:25px;}
.f{ background-position:-145px -120px;width:25px; height:25px;}
.g{ background-position:-21px -120px;width:25px; height:25px;}
.h{ background-position:-21px -120px;width:25px; height:25px;}
.i{ background-position:-21px -120px;width:25px; height:25px;}

</style>
</head>

<body>

<div class="div1">
<ul>
    <li><span class="a"></span><a href=http://www.mamicode.com/"#">aaaaa
    <li><span class="b"></span><a href=http://www.mamicode.com/"#">bbbbb
    <li ><span class="c"></span><a href=http://www.mamicode.com/"#">ccccc
    <li ><span class="d"></span><a href=http://www.mamicode.com/"#">ddddd
    <li ><span class="e"></span><a href=http://www.mamicode.com/"#">eeeee
    <li ><span class="f"></span><a href=http://www.mamicode.com/"#">eeeee
    <li ><span class="g"></span><a href=http://www.mamicode.com/"#">eeeee
    <li ><span class="h"></span><a href=http://www.mamicode.com/"#">eeeee
</ul>
 </div>
</body>
</html>


CSS精灵写法