使用vw实现模仿哔哩哔哩移动端案例

这是一个关于如何使用vw单位实现哔哩哔哩移动端页面适配的案例。HTML代码展示了包含头部区域和主体内容的布局,包括导航栏、搜索、登录、下载等元素以及视频卡片的展示。CSS样式通过less预处理器进行编写,利用vw单位确保元素尺寸按屏幕宽度比例缩放,实现了响应式布局。
摘要由CSDN通过智能技术生成

  使用vw实现哔哩哔哩移动端适配案例效果图如下  

 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" />
    <title>B站</title>
    <link rel="stylesheet" href="./fonts/iconfont.css" />
    <link rel="stylesheet" href="./css/index.css" />
  </head>
  <body>
    <!-- 头部区域开始 -->
    <header>
      <div class="top">
        <div class="left">
          <a href="#">
            <i class="iconfont Navbar_logo"></i>
          </a>
        </div>
        <div class="right">
          <a href="#">
            <i class="iconfont ic_search_tab"></i>
          </a>
          <a href="#">
            <img src="./images/login.png" alt="" />
          </a>
          <a href="#">
            <img src="./images/download.png" alt="" />
          </a>
        </div>
      </div>
      <div class="bottom">
        <div class="tob">
          <ul>
            <li>
              <a href="#" class="active">首页</a>
            </li>
            <li>
              <a href="#">动画</a>
            </li>
            <li>
              <a href="#">番剧</a>
            </li>
            <li>
              <a href="#">国创</a>
            </li>
            <li>
              <a href="#">音乐</a>
            </li>
          </ul>
        </div>
        <div class="more">
          <a href="#">
            <i class="iconfont general_pulldown_s"></i>
          </a>
        </div>
      </div>
    </header>
    <!-- 头部区域结束 -->
    <!-- 主体内容开始 -->
    <section>
      <a href="#">
        <div class="pic">
          <img src="./images/1.jpg" alt="" />
          <div class="count">
            <p>
              <i class="iconfont icon_shipin_bofangshu"></i>
              <span>132万</span>
            </p>
            <p>
              <i class="iconfont icon_shipin_danmushu"></i>
              <span>2.4万</span>
            </p>
          </div>
        </div>
        <div class="txt">
          你活着补刀就是对我最大的侮辱,韩服最强王者组单杀集锦#19
        </div>
      </a>
      <a href="#">
        <div class="pic">
          <img src="./images/2.jpg" alt="" />
          <div class="count">
            <p>
              <i class="iconfont icon_shipin_bofangshu"></i>
              <span>132万</span>
            </p>
            <p>
              <i class="iconfont icon_shipin_danmushu"></i>
              <span>2.4万</span>
            </p>
          </div>
        </div>
        <div class="txt">
          你活着补刀就是对我最大的侮辱,韩服最强王者组单杀集锦#19
        </div>
      </a>
      <a href="#">
        <div class="pic">
          <img src="./images/1.jpg" alt="" />
          <div class="count">
            <p>
              <i class="iconfont icon_shipin_bofangshu"></i>
              <span>132万</span>
            </p>
            <p>
              <i class="iconfont icon_shipin_danmushu"></i>
              <span>2.4万</span>
            </p>
          </div>
        </div>
        <div class="txt">
          你活着补刀就是对我最大的侮辱,韩服最强王者组单杀集锦#19
        </div>
      </a>
      <a href="#">
        <div class="pic">
          <img src="./images/2.jpg" alt="" />
          <div class="count">
            <p>
              <i class="iconfont icon_shipin_bofangshu"></i>
              <span>132万</span>
            </p>
            <p>
              <i class="iconfont icon_shipin_danmushu"></i>
              <span>2.4万</span>
            </p>
          </div>
        </div>
        <div class="txt">
          你活着补刀就是对我最大的侮辱,韩服最强王者组单杀集锦#19
        </div>
      </a>
      <a href="#">
        <div class="pic">
          <img src="./images/1.jpg" alt="" />
          <div class="count">
            <p>
              <i class="iconfont icon_shipin_bofangshu"></i>
              <span>132万</span>
            </p>
            <p>
              <i class="iconfont icon_shipin_danmushu"></i>
              <span>2.4万</span>
            </p>
          </div>
        </div>
        <div class="txt">
          你活着补刀就是对我最大的侮辱,韩服最强王者组单杀集锦#19
        </div>
      </a>
      <a href="#">
        <div class="pic">
          <img src="./images/2.jpg" alt="" />
          <div class="count">
            <p>
              <i class="iconfont icon_shipin_bofangshu"></i>
              <span>132万</span>
            </p>
            <p>
              <i class="iconfont icon_shipin_danmushu"></i>
              <span>2.4万</span>
            </p>
          </div>
        </div>
        <div class="txt">
          你活着补刀就是对我最大的侮辱,韩服最强王者组单杀集锦#19
        </div>
      </a>
      <a href="#">
        <div class="pic">
          <img src="./images/1.jpg" alt="" />
          <div class="count">
            <p>
              <i class="iconfont icon_shipin_bofangshu"></i>
              <span>132万</span>
            </p>
            <p>
              <i class="iconfont icon_shipin_danmushu"></i>
              <span>2.4万</span>
            </p>
          </div>
        </div>
        <div class="txt">
          你活着补刀就是对我最大的侮辱,韩服最强王者组单杀集锦#19
        </div>
      </a>
      <a href="#">
        <div class="pic">
          <img src="./images/2.jpg" alt="" />
          <div class="count">
            <p>
              <i class="iconfont icon_shipin_bofangshu"></i>
              <span>132万</span>
            </p>
            <p>
              <i class="iconfont icon_shipin_danmushu"></i>
              <span>2.4万</span>
            </p>
          </div>
        </div>
        <div class="txt">
          你活着补刀就是对我最大的侮辱,韩服最强王者组单杀集锦#19
        </div>
      </a>
      <a href="#">
        <div class="pic">
          <img src="./images/1.jpg" alt="" />
          <div class="count">
            <p>
              <i class="iconfont icon_shipin_bofangshu"></i>
              <span>132万</span>
            </p>
            <p>
              <i class="iconfont icon_shipin_danmushu"></i>
              <span>2.4万</span>
            </p>
          </div>
        </div>
        <div class="txt">
          你活着补刀就是对我最大的侮辱,韩服最强王者组单杀集锦#19
        </div>
      </a>
      <a href="#">
        <div class="pic">
          <img src="./images/2.jpg" alt="" />
          <div class="count">
            <p>
              <i class="iconfont icon_shipin_bofangshu"></i>
              <span>132万</span>
            </p>
            <p>
              <i class="iconfont icon_shipin_danmushu"></i>
              <span>2.4万</span>
            </p>
          </div>
        </div>
        <div class="txt">
          你活着补刀就是对我最大的侮辱,韩服最强王者组单杀集锦#19
        </div>
      </a>
    </section>
    <!-- 主体内容结束 -->
  </body>
</html>

base.less代码如下:

// out:false

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
  }
  
  body {
    font-family: Helvetica Neue,Tahoma,Arial,PingFangSC-Regular,Hiragino Sans GB,Microsoft Yahei,sans-serif;
  }
  
  a {
    color: #333;
    text-decoration: none;
  }
  
  img {
    vertical-align: middle;
    width: 100%;
    height: 100%;
  }
  ul {
    list-style: none;
  }
  
  .ellipsis-2 {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

 

index.less代码如下:

@import "./base.less";

@vw: 3.75vw;
// 头部样式
header {
  z-index: 999;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: (84 / @vw);
  background-color: #fff;
  .top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: (44 / @vw);
    padding: 0 (12 / @vw) 0 (18 / @vw);
    .left {
      .Navbar_logo {
        color: #fb7299;
        font-size: (28 / @vw);
      }
    }
    .right {
      display: flex;
      width: (166 / @vw);
      justify-content: space-between;
      height: (24 / @vw);
      i {
        font-size: (22 / @vw);
        color: #ccc;
      }
    }
  }
  .bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: (40 / @vw);
    border-bottom: 1px solid #eee;
    .tob {
      ul {
        display: flex;
        flex: 1;
        justify-content: space-between;
        li {
          padding: 0 (16 / @vw);
          a {
            display: block;
            height: (38 / @vw);
            line-height: (36 / @vw);
            font-size: (14 / @vw);
            &.active {
              color: #fb7299;
              border-bottom: 2px solid #fb7299;
            }
          }
        }
      }
    }
    .more {
      text-align: center;
      width: (40 / @vw);
      height: (40 / @vw);
      line-height: (40 / @vw);
      i {
        font-size: (22 / @vw);
        color: #ccc;
      }
    }
  }
}
// 主体样式
section {
  padding: (5 / @vw);
  display: flex;
  flex-wrap: wrap;
  padding-top: (84 / @vw);
  a {
    width: 50%;
    padding: (8 / @vw) (5 / @vw);
    .pic {
      position: relative;
      .count {
        position: absolute;
        left: 0;
        bottom: 0;
        display: flex;
        justify-content: space-between;
        width: 100%;
        padding: (8 / @vw);
        background-image: linear-gradient(
          to top,
          rgba(0, 0, 0, 0.6),
          rgba(0, 0, 0, 0)
        );
        color: #fff;
        p {
          font-size: (12 / @vw);
          i {
            vertical-align: middle;
          }
        }
      }
    }
    .txt {
      margin-top: (5 / @vw);
      font-size: (12 / @vw);
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值