web前端20200313学习笔记

1.精灵技术讲解

CSS精灵其实是将网页中的一些背景图整合到一张大图中(精灵图),然而,各个网页元素通常只需要精灵图中不同位置的某个小图,要想精确定位到精灵图中的某个小图

1.1精灵技术使用核心总结

首先我们知道,css精灵技术主要针对背景图片,插入的图片img是不需要这个技术的
  • 1,精确测量,每个小背景图片的大小和位置。
  • 2,给盒子指定小背景图片时,背景定位基本都是负数。
  • 举例:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .icon1{
            width: 23px;
            height: 23px;
            background: url("imgs/index.png") no-repeat;

            background-position: 0 -107px;            
        }
        .icon2{
            width: 23px;
            height: 23px;
            background:url("imgs/index.png") no-repeat;
            background-position: -157px -107px;            
          
        }

    </style>
</head>
<body>
    <div>
        <div class="icon1"></div>
        <div class="icon2"></div>
    </div>
</body>
</html>

在这里插入图片描述

1.3精灵图的制作

css精灵其实是将网页中的一些背景图像整合到一张大图中(精灵图),那我们要做的就是把小图拼合成一张大图。
大部分情况下,精灵图都是由网页美工做。

2.滑动门原理

举例:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* 1.a是设置左侧背景图片的
        2.span是设置右侧背景
        3.因为整个导航栏都是链接 
        4.因为我们是滑动门左右推拉跟文字内容有关系就要用到行内块元素*/
        a{
            display: inline-block;
            height: 33px;
            background:url(imgs/to.png) no-repeat;
            margin: 100px;
            padding-left: 15px;
            color: #fff;
        }
        a span{
            display: inline-block;
            height: 33px;
            padding-right: 15px;
            /* 一定注意span需要图片右对齐 */
            background:url(imgs/to.png) no-repeat right top;
        }
    </style>
</head>
<body>
    <a href="#">
        
        <span>首页</span>
    </a>
</body>
</html>

运行结果:

在这里插入图片描述

3.微信导航栏案例

举例:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            
        }
        li{
            list-style: none;
            float: left;
            margin:0 5px;

        }
        body{
            background:url(imgs/wx.jpg) repeat-x;
        }
        .nav a{
            display: inline-block;
            height: 33px;
            background:url(imgs/to.png) no-repeat;
            padding-left: 15px;
            color: #fff;
            font-size: 14px;
            
        }
        .nav span{
            display:inline-block;
            height: 33px;
            background:url(imgs/to.png) no-repeat right;
            padding-right: 15px;
            line-height: 33px;
        }
        .nav{
            margin-top:20px;
         
        }
        /* .nav a:hover{
            background-image: url(imgs/ao.png);
            
        }
        .nav a:hover span{
            background-image: url(imgs/ao.png);
        } */

        .nav a:hover,
        .nav a:hover span{
            background-image: url(imgs/ao.png);
        }

    </style>
</head>
<body>
    <div class="nav">
        <ul>
            <li>
                <a href="#">
                    <span>首页</span>
                </a>
            </li>
            <li>
                <a href="#">
                    <span>帮助与反馈</span>
                </a>
            </li>
            <li>
                <a href="#">
                    <span>公众平台</span>
                </a>
            </li>
            <li>
                <a href="#">
                    <span>开放平台</span>
                </a>
            </li>
        </ul>
    </div>
</body>
</html>

运行结果:
在这里插入图片描述

在这里插入图片描述

4.margin之美

  • 负边距+定位:水平居中
    利用父级盒子的50%,然后往左边走自己宽度的一半,可以实现盒子水平垂直居中
  • 压住盒子相邻边距
    举例:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 200px;
            height: 300px;
            border: 1px solid #ccc;
            float: left;
            margin-left: -1px;
            margin-top:-1px;
        }
    </style>
</head>
<body>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值