
1、將頁面所涉及的所有零星背景影像集中到大圖中,然後將大圖用於網頁。當使用者造訪頁面時,只需向伺服器發送一次請求。
2.直接使用background-position等屬性來準確定位所需的背景部分。
實例
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div>
<span></span>
<span></span>
<span></span>
</div>
</body>
<style>
.box span {
display: inline-block;
}
.j {
background: url("abcd.jpg") no-repeat -389px -141px;
width: 102px;
height: 112px;
}
.w {
background: url("abcd.jpg") no-repeat -117px -560px;
width: 135px;
height: 112px;
}
.t {
background: url("abcd.jpg") no-repeat -368px -417px;
width: 102px;
height: 112px;
}
</style>
</html>以上就是css精靈圖技術的介紹,希望對大家有幫助。