移动web第一天之案例

本文通过四个示例详细介绍了如何使用HTML和CSS实现网页动态效果,包括购物车字体图标、双开门位移效果、图片缩放以及位移+缩放+渐变的综合效果。每个案例都提供了完整代码,并强调动态效果需运行查看。这些技巧在前端开发中常用于提升用户体验。
摘要由CSDN通过智能技术生成

《移动web第一天》文章里的内容完成各案例


一、购物车【字体图标】

在这里插入图片描述

<!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>
  <meta name="description" content="网页描述">
  <meta name="keywords" content="网页关键字">
  <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
  <!-- 引入字体图标样式表 -->
  <link rel="stylesheet" href="./iconfont/iconfont.css">
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    li {
      list-style: none;
    }

    a {
      color: #333;
      text-decoration: none;
    }

    .nav {
      width: 200px;
      margin: 50px auto;
      font-size: 18px;
    }

    .orange {
      color: orange;
    }
  </style>
</head>

<body>
  <div class="nav">
    <ul>
      <li>
        <span class="iconfont icon-cart-Empty-fill orange"></span>
        <span>购物车</span>
        <span class="iconfont icon-arrow-down"></span>
      </li>
    </ul>
  </div>
</body>

</html>

二、双开门【位移】

注:此图应是动态效果,建议代码运行查看
在这里插入图片描述

<!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">
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    .box{
      width: 1366px;
      height: 600px;
      margin: 20px auto;
      background-image: url(./images/bg.jpg);
      /* 超出盒子部分隐藏 */
      overflow: hidden;
    }
    .left,
    .right{
      float: left;
      width: 683px;
      height: 600px;
      background-image: url(./images/fm.jpg);
      /* 过渡 */
      transition: all 2s;
    }
    .right{
      background-position: right 0;
    }
    .box:hover .left{
      transform: translateX(-100%);
    }
    .box:hover .right{
      transform: translateX(100%);
    }
  </style>
</head>

<body>
  <div class="box">
    <div class="left"></div>
    <div class="right"></div>
  </div>
</body>

</html>

三、缩放

注:此图应是动态效果,建议代码运行查看
在这里插入图片描述

<!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">
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .box {
      width: 1066px;
      height: 664px;
      margin: 20px auto;
      background-image: url(./images/bg.jpg);
      text-align: center;
    }

    img {
      width: 660px;
      opacity: 0;
      /* 过渡 */
      transition: all 1s;
    }

    .box:hover img {
      transform: scale(0.2);
      opacity: 1;
    }
  </style>
</head>

<body>
  <div class="box">
    <img src="./images/play.png" alt="">
  </div>
</body>

</html>

四、位移+缩放+渐变综合

鼠标悬停时效果:
在这里插入图片描述

<!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">
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .box {
      position: relative;
      margin: 20px;
      width: 300px;
      height: 187px;
      overflow: hidden;
    }
    .box img{
      width: 300px;
      transition: all .5s;
    }
    .box .title{
      position: absolute;
      left: 15px;
      bottom: -25px;
      z-index: 2;
      width: 260px;
      color: #fff;
      font-size: 20px;
      font-weight: 700;
      transition: transform .7s;
    }
    .box .title p{
      margin-top: 20px;
    }
    .box .mask{
      position: absolute;
      left: 0;
      top: 0;
      opacity: 0;
      width: 300px;
      height: 187px;
      background-image: linear-gradient(transparent,rgba(0,0,0,.6));
    } 
    .box:hover img{
      transform: scale(1.3);
    }
    .box:hover .title{
      transform: translate(0,-50%) ;
    }
    .box:hover .mask{
      opacity: 1;
    }
  </style>
</head>

<body>
  <div class="box">
    <img src="./images/9.jpeg" alt="">
    <div class="title">常见后即可免费与<p>了解更多</p></div>
    <div class="mask"></div>
  </div>
</body>

</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值