pink前端--小知识点汇总 练手小案例

一  用子绝夫相定位模式 : 当鼠标经过时 出现遮罩层

1.1

代码

<!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>
        .tudou {
            /* 相对定位 */
            position: relative;
            width: 402px;
            height: 220px;
            margin: 30px auto;
        }
        .tudou img {
            width: 100%;
            height: 100%;
        }
        .mask {
            /* 隐藏遮罩层 */
            display: none;
            /* 绝对定位 */
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,.3) url(/前端小案例总和/img/title_sprite.png) no-repeat center;
        }
/* 当我们鼠标经过父盒子时 让里面遮罩层显示 */
      .tudou:hover .mask{
        display: block;
      }

      
    </style>
</head>
<body>
    
    <div class="tudou">
    <div class="mask"></div>
    <img src="img/tudou.png" alt="">
    </div>
</body>
</html>

效果

 

二  精灵图的用法

将多个小背景图片整合到一个大照片中 使用backgroung -position :x,y;来实现定位不同图片位置

 

<!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>
        .box1 {
            width: 60px;
            height: 60px;
            background-color: pink;
            margin: 100px auto;
            background: url(img/sprites.png) no-repeat -182px 0 ;
        }

        .box2 {
            width: 27px;
            height: 25px;
            margin: 200px auto;
             background: url(img/sprites.png) no-repeat -155px -106px;
        }

    </style>
</head>
<body>
    <div class="box1">

    </div>
    <div class="box2"></div>
</body>
</html>
<!-- 将多个小背景图片整合到一个大照片中
     使用backgroung -position :x,y;来实现定位
     不同图片位置
    字体图标 轻量级 -->

三  css三角形制作

<!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>
        .box1 {
            
            width: 0;
            height: 0;
          
            border-top: 20px solid #b9d8ab;
            border-right:20px solid #d3d8ab;
            border-left: 20px solid palegoldenrod;
            border-bottom: 20px solid paleturquoise;

        }
        .box2 {
            width: 0;
            height: 0;
            margin: 100px auto;
            border: 10px solid transparent;
            border-bottom-color: red;
        }
        .box {
           position: relative;
            width: 120px;
            height: 249px;
            background-color: pink;

        }
        .box span {
            position: absolute;
            right: 15px;
            top: -9px;
            height: 0;
            width: 0;
            line-height: 0;
            font-size: 0;
            border: 5px solid transparent;
            border-bottom-color: pink;

        }
        .box3 {
            position: relative;
            height: 200px;
            width: 400px;
            background-color: #d3d8ab;
        }
        .box3 span{
            position: absolute;
            top: 90px;
            right: -40px;
            height: 0;
            width: 0;
            line-height: 0;
            font-size: 0;
            border: 20px solid transparent;
            border-left-color:#d3d8ab;
        }
    </style>
</head>
<body>
    <div class="box1"></div>
    <div class="box2"></div>
    <div class="box">
        <span></span>
    </div>
    <div class="box3">
        <span></span>
    </div>
</body>
</html>

效果

 

四  解决图片底侧空白缝隙问题 vertical-align: middle;

行内块元素会和文字的基线对齐 

  使行内或行内块元素垂直居中 

<!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>
        img {
            width: 400px;
            height: 300px;
            vertical-align: middle;
        }
    </style>
</head>
<body>
    <!-- 行内块元素会和文字的基线对齐 -->
    <!-- 使行内或行内块元素垂直居中 -->
    <img src="img/erji.jpg" alt="">耳机耳机
    <!-- 解决图片底侧空白缝隙 问题-->
    
</body>
</html>

效果:使文字 居于图片中间

 

五  省略号代替未显示文本

<!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>
        .box {
            width: 150px;
            height: 80px;
            background-color: pink;
            margin: 100px auto;
            /* white-space默认值是normal 表示文字显示不开自动换行 */
            /* 1.强制文字在同一行 */
            white-space: nowrap;
            /* 2.隐藏溢出文字 */
            overflow: hidden;
            /* 3.溢出文字用省略号代替 */
            text-overflow: ellipsis;
        }
        .box1 {
            width: 150px;
            height: 65px;
            background-color: pink;
            margin: 200px auto;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 3;
            -webkit-box-orient: vertical;
        }
    </style>
</head>
<body>
    <!-- 强制转化单行文字 -->
    <div class="box">
  啥也不说,但是此处省略一万字呀
    </div>
    <div class="box1">
啥也不说,但是此处省略一万字呀啥也不说,但是此处省略一万字呀啥也不说,
但是此处省略一万啥也不说,
    </div>
</body>
</html>

效果

 

六  margin负值巧妙应用 

当鼠标经过盒子时 边框均匀变色

<!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>
      ul li {
        position: relative;
        float: left;
        list-style: none;
        width: 150px;
        height: 200px;
        border: 1px solid red;
        margin-left: -1px;
      }
      /* 盒子没定位 鼠标经过添加相对定位 */
      /* ul li:hover {
            position: relative;
            border: 1px solid blue;
        }*/
      /* 盒子一般是有定位的 */
      ul li:hover {
        z-index: 1;
        border: 1px solid blue;
      }
    </style>
  </head>
  <body>
    <div>
      <ul>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
      </ul>
    </div>
  </body>
</html>

效果 鼠标经过在后一个盒子 盒子变色

 

七 行内块元素应用 写页码

代码

<!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;
      }
      .box {
        /* 使盒子整体居中 */
        text-align: center;
        margin: 20px auto;
      }
      .box a {
        display: inline-block;
        width: 36px;
        height: 36px;
        text-align: center;
        line-height: 36px;
        background-color: #f7f7f7;
        border: 1px solid #ccc;
        color: #333;
        text-decoration: none;
      }

      .box .prev {
        width: 80px;
      }
      .box .courrent {
        background-color: #fff;
        border: #fff;
      }
      .box .text {
        height: 32px;
        width: 34px;
        border: 1px solid #ccc;
      }
      .box .anniu {
        width: 45px;
        height: 36px;
        border: 1px solid #ccc;
        font-size: 14px;
        color: #333;
        outline: none;
      }
    </style>
  </head>
  <body>
    <!-- 对于行内块元素 给父盒子text-align:center;
        就可以给里面的所有子盒子水平居中 -->
    <div class="box">
      <a href="#" class="prev">&lt;&lt;上一页</a>
      <a href="#">1</a>
      <a href="#" class="courrent">2</a>
      <a href="#">3</a>
      <a href="#">4</a>
      <a href="#">5</a>
      <a href="#" class="courrent">...</a>
      <a href="#" class="prev">下一页>></a>
      到第
      <input type="text" class="text" />
      页
      <button class="anniu">确定</button>
    </div>
  </body>
</html>

效果

 

八 京东css三角样式

<!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;
        }
        .box {
            width: 0;
            height: 0;
            border-top: 100px solid #fff;
            border-right: 50px solid #eb1313;
            border-bottom: 0 solid #d4bcaa;
            border-left: 0px solid #dabae6;
        }
        .box2 {
            width: 0;
            height: 0;
            border-color: transparent red transparent transparent;
            border-style: solid;
            border-width: 22px 10px 0 0;
        }

        .box3 {
            
            width: 160px;
            height: 24px;
            text-align: center;
            line-height: 24px;
            border: 1px solid red;
            margin: 100px auto;
            
        }
        .low {
            position: relative;
            float: left;
            width: 90px;
            height: 100%;
            font-weight: 700;
            color: #fff;
            background-color: red;
        }

        .low i {
            position: absolute;
            right: 0;
            top: 0;
            width: 0;
            height: 0;
            border-color: transparent #fff transparent transparent;
            border-style: solid;
            border-width: 24px 10px 0 0;

        }
        .high {

            font-size: 12px;
            color: gray;
            
            text-decoration: line-through;
        }
    </style>
</head>
<body>
    <div class="box">

    </div>
    <div class="box2"></div>
    <div class="box3">
        <span class="low">$1190
            <i></i>
        </span>
        <span class="high">$2990</span>
    </div>
</body>
</html>

效果

 

九 淘宝焦点图

代码

<!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>
      * {
        padding: 0;
        margin: 0;
      }
      .tb-promo {
        position: relative;
        width: 600px;
        height: 250px;
        margin: 100px auto;
      }
      .tb-promo img {
        width: 100%;
        height: 100%;
      }
      .right {
        right: 0;
      }
      .left {
        left: 0;
      }
      /* 也可以用并集选择器 减少代码 */
      /* 如果一个盒子既有left也有right 只会执行左侧按钮 */
      .left,
      .right {
        position: absolute;
        height: 20px;
        width: 20px;
        text-decoration: none;
        line-height: 20px;
        top: 50%;
        margin-top: -15px;
        background: rgba(0, 0, 0, 0.3);
        text-align: center;
        color: #fff;
      }
    </style>
  </head>
  <body>
    <div class="tb-promo">
      <img src="img/taobao.png" alt="" />
      <a href="#" class="left"><</a>
      <a href="#" class="right">></a>
    </div>
  </body>
</html>

效果

 

十 过度  进度条效果

 谁改变给谁加 是让子盒子变化 所有给子盒子加 。时间后面一定要加上时间单位s 

<!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>
      .box {
        height: 20px;
        width: 250px;
        border: 2px solid red;
        border-radius: 9px;
        padding: 0.5px;
      }
      .du {
        height: 100%;
        width: 50%;
        background-color: red;
        transition: all 0.8s;
        /* 谁改变给谁加 是让子盒子变化 所有给子盒子加 */
        /* 时间后面一定要加上时间单位s */
      }
      /* 让鼠标经过父盒子使 子盒子进度变化 */
      .box:hover .du {
        width: 100%;
        transition: all 0.8;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <div class="du"></div>
    </div>
  </body>
</html>

效果 鼠标在盒子上 进度条逐渐增加

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值