首页 > 文章列表 > css精灵图技术是什么

css精灵图技术是什么

css 精灵图技术
400 2022-08-06

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>