使用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;
}
}
}