博客列表 >根据css背景图属性+css定位制作雪碧图效果

根据css背景图属性+css定位制作雪碧图效果

李盛滔
李盛滔原创
2022年05月10日 17:15:56491浏览

根据css背景图属性+css定位制作雪碧图效果1.jpg

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>雪碧图</title>
    <style>
        div{
            width: 100px;
            height: 100px;
            background-image: url('https://img.php.cn/upload/image/587/391/184/1652174108167035.jpg');
            background-repeat: no-repeat;
            background-position: center;
            padding: 0;
        }
        .box{
            width: 300px;
            height: 300px;
            background-image: none;
            position: relative;
        }
        .box1 {
            background-position: -11px -8px;
        }
        .box2 {
            background-position: -121px -8px;
            position: absolute;
            left:100px;
            top: 0;
        }
        .box3 {
            background-position: -231px -8px;
            position: absolute;
            left:200px;
            top: 0;
        }
        .box4 {
            background-position: -341px -8px;
            position: absolute;
            left: 0;
            top: 100px;
        }
        .box5 {
            background-position: -451px -8px;
            position: absolute;
            left: 100px;
            top: 100px;
        }
        .box6 {
            background-position: -561px -8px;
            position: absolute;
            left: 200px;
            top: 100px;
        }
        .box7 {
            background-position: -671px -8px;
            position: absolute;
            left: 0;
            top: 200px;
        }
        .box8 {
            background-position: -781px -8px;
            position: absolute;
            left: 100px;
            top: 200px;
        }
        .box9 {
            background-position: -891px -8px;
            position: absolute;
            left: 200px;
            top: 200px;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="box1"></div>
        <div class="box2"></div>
        <div class="box3"></div>
        <div class="box4"></div>
        <div class="box5"></div>
        <div class="box6"></div>
        <div class="box7"></div>
        <div class="box8"></div>
        <div class="box9"></div>
    </div>
    
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例


声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议