雪碧圖:多個圖片集成在一個圖片中的圖
使用雪碧圖可以減少網絡請求的次數,加快運行的速度。
例如要使用下面的雪碧圖:需要用到background-position屬性
代碼示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
#container div{ /* 空格 后代選擇器:選中下面的所有的div*/
height: 25px;
width: 25px;
color: red;
background-image: url("../../img/ico1.gif");
}
#div2{
background-position: -42px 0;/*圖片往左移動42個px*/
}
#div3{
background-position: -165px -28px;/*圖片往左移動165個px 圖片向上移動28個px*/
}
</style>
<title>雪碧圖</title>
</head>
<body>
<div id="container">
<div></div>
<div id="div2"></div>
<div id="div3"></div>
</div>
</body>
</html>
代碼運行結果:
---------------------
原文:https://blog.csdn.net/xuehyunyu/article/details/72773727