精灵图介绍及使用

2 精灵图

2.1 什么是精灵图

CSS Sprites 也称之为精灵图或雪碧图,是一种背景图片的应用处理方式,将很多小图片合并到到一张大图中去。把整个大图作为背景图,然后通过 background-position 属性讲合适的图片显示到元素上。

2.2 精灵图的优点

多个元素使用的只一张背景图像,减少图片的请求次数,图片只需下载一次。
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        div{
            display: inline-block;
            background: url(images/abcd.jpg) no-repeat;
        }
        .aa{
            width: 108px;
            height: 110px;
            background-position: 0 -9px;
        }
        .nn{
            width: 112px;
            height: 110px;
            background-position: -255px -276px;
        }
        .dd{
            width: 97px;
            height: 107px;
            background-position: -363px -8px;
        }
        .yy{
            width: 110px;
            height: 110px;
            background-position: -367px -556px;
        }
    </style>
</head>
<body>
    <div class="aa"></div>
    <div class="nn"></div>
    <div class="dd"></div>
    <div class="yy"></div>
</body>
</html>

2.4 background-position

background-position 可以调整背景图像的位置,三种方式可以设置位置

使用关键字:

background-position: left top;
background-position: right;
background-position: top;
/* left right center*/
/* top bottom center*/

通过长度设置图像左上角在元素上的坐标:

background-position: 100px 20px;
background-position; 20px; /* 20px center */

使用百分比设置背景图像位置:

background-position: 30% 30%;
/* 背景图像上 30%,30%的点 与 元素上 30%,30% 的点重合 */

3 页面布局

3.1 样式重置

1. reset.css
2. normalize.css

3.2 版心

.container {
    margin: 0 auto;
    width: 1000px;
}

4 favicon 图标

<link rel="shortcut icon" href="favicon.ico">

ico 制作工具:

  • 在线工具 http://www.ico51.cn/
  • 在线工具 http://www.bitbug.net/
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值