<!DOCTYPE html>
<html lang="zh-CN">
<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>
</head>
<body>
<!-- DPR:设备像素比,设备显示和页面CSS之间的比值 -->
<!-- 布局视图:通常是980px width-->
<!-- 视觉视图:375px 手机宽度device-width-->
<!-- 第一步:修改布局试图,让布局试图=视觉视图:width = device-width -->
<!-- 第二步:初始化:initial-scale=1.0 理想视图 = 视觉视图,布局试图/视觉视图 = 1 : 1 -->
<!-- 主流解决方案:rem + vw -->
<!-- 手机端将px全部转换成rem,插件px to rem & rpx(cssrem) -->
<!-- 默认 1rem = 16px 为了计算方便,可以自己修改成:100px = 1rem -->
<div class="box">hello</div>
<style>
/* html = :root */
html {
/* 设置根字号 */
/* 以iphone11为例: */
/* 设计稿宽750px,DPR = 2 , iphone11手机视觉视图device-width为375px */
/* device-width = width / DPR = 750px / 2 = 375px */
/* 100vw = 375px =100% */
/* 1vw = 375px / 100 = 3.75 */
/* 100px = 100vw /3.75 = 375px / 3.75 */
/* font-size: 100px; */
font-size: calc(100vw / 3.75);
}
body {
/* 在body将font-size还原成浏览器默认值16px */
font-size: 0.16rem;
}
.box {
width: 2rem;
height: 0.5rem;
border: 1px solid #000;
background-color: lightgreen;
}
/* 媒体查询:宽度最小300px时字体不再变小 */
@media screen and (max-width: 300px) {
:root {
font-size: 85px;
}
}
/* 媒体查询:宽度最大600px时字体不再变大 */
@media screen and (min-width: 600px) {
:root {
font-size: 170px;
}
}
</style>
</body>
</html>
<!DOCTYPE html>
<html lang="zh-CN">
<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>
<link rel="stylesheet" href="font_icon/iconfont.css" />
<link rel="stylesheet" href="css/reset.css" />
<link rel="stylesheet" href="css/header.css" />
<link rel="stylesheet" href="css/footer.css" />
<link rel="stylesheet" href="css/main.css" />
</head>
<body style="height: 1500px">
<!-- 头部 -->
<header>
<!-- 顶部 -->
<div class="top">
<div class="logo iconfont icon-shejiaotubiao-08"></div>
<div class="search">
<div class="keys">
<span class="iconfont icon-fangdajing"></span>
<span>寻找宝贝店铺</span>
</div>
</div>
</div>
<!-- 轮播图 -->
<div class="slider">
<a href=""><img src="images/banner/banner1.jpg" alt="" /></a>
</div>
<!-- 导航 -->
<ul class="nav">
<li class="item">
<a href=""><img src="images/nav/nav1.png" /></a>
<a href="">天猫新品</a>
</li>
<li class="item">
<a href=""><img src="images/nav/nav2.png" /></a>
<a href="">天猫新品</a>
</li>
<li class="item">
<a href=""><img src="images/nav/nav3.png" /></a>
<a href="">天猫新品</a>
</li>
<li class="item">
<a href=""><img src="images/nav/nav4.png" /></a>
<a href="">天猫新品</a>
</li>
<li class="item">
<a href=""><img src="images/nav/nav5.png" /></a>
<a href="">天猫新品</a>
</li>
<li class="item">
<a href=""><img src="images/nav/nav6.png" /></a>
<a href="">天猫新品</a>
</li>
<li class="item">
<a href=""><img src="images/nav/nav7.png" /></a>
<a href="">天猫新品</a>
</li>
<li class="item">
<a href=""><img src="images/nav/nav2.png" /></a>
<a href="">天猫新品</a>
</li>
<li class="item">
<a href=""><img src="images/nav/nav3.png" /></a>
<a href="">天猫新品</a>
</li>
<li class="item">
<a href=""><img src="images/nav/nav4.png" /></a>
<a href="">天猫新品</a>
</li>
</ul>
</header>
<!-- 主体 -->
<main>
<div class="list">
<div class="title">
<img src="https://img.alicdn.com/tfs/TB1V2eQrKSSBuNjy0FlXXbBpVXa-966-114.png" />
</div>
<ul class="unit">
<li class="item">
<div class="img">
<img
src="//gw.alicdn.com/bao/uploaded/i2/1029692622/O1CN01QhCTWy1VEvEKiClVv_!!1029692622.jpg_320x320q90.jpg_.webp"
alt=""
/>
</div>
<div class="detail">
<div class="desc">商品描述商品描述<br />商品描述商品描述midk</div>
<div class="price">
<span class="iconfont icon-rmb">89</span><span class="num">45人已购买</span>
</div>
</div>
</li>
<li class="item">
<div class="img">
<img
src="//gw.alicdn.com/bao/uploaded/i2/1029692622/O1CN01QhCTWy1VEvEKiClVv_!!1029692622.jpg_320x320q90.jpg_.webp"
alt=""
/>
</div>
<div class="detail">
<div class="desc">商品描述商品描述<br />商品描述商品描述midk</div>
<div class="price">
<span class="iconfont icon-rmb">89</span><span class="num">45人已购买</span>
</div>
</div>
</li>
<li class="item">
<div class="img">
<img
src="//gw.alicdn.com/bao/uploaded/i2/1029692622/O1CN01QhCTWy1VEvEKiClVv_!!1029692622.jpg_320x320q90.jpg_.webp"
alt=""
/>
</div>
<div class="detail">
<div class="desc">商品描述商品描述<br />商品描述商品描述midk</div>
<div class="price">
<span class="iconfont icon-rmb">89</span><span class="num">45人已购买</span>
</div>
</div>
</li>
<li class="item">
<div class="img">
<img
src="//gw.alicdn.com/bao/uploaded/i2/1029692622/O1CN01QhCTWy1VEvEKiClVv_!!1029692622.jpg_320x320q90.jpg_.webp"
alt=""
/>
</div>
<div class="detail">
<div class="desc">商品描述商品描述<br />商品描述商品描述midk</div>
<div class="price">
<span class="iconfont icon-rmb">89</span><span class="num">45人已购买</span>
</div>
</div>
</li>
<li class="item">
<div class="img">
<img
src="//gw.alicdn.com/bao/uploaded/i2/1029692622/O1CN01QhCTWy1VEvEKiClVv_!!1029692622.jpg_320x320q90.jpg_.webp"
alt=""
/>
</div>
<div class="detail">
<div class="desc">商品描述商品描述<br />商品描述商品描述midk</div>
<div class="price">
<span class="iconfont icon-rmb">89</span><span class="num">45人已购买</span>
</div>
</div>
</li>
<li class="item">
<div class="img">
<img
src="//gw.alicdn.com/bao/uploaded/i2/1029692622/O1CN01QhCTWy1VEvEKiClVv_!!1029692622.jpg_320x320q90.jpg_.webp"
alt=""
/>
</div>
<div class="detail">
<div class="desc">商品描述商品描述<br />商品描述商品描述midk</div>
<div class="price">
<span class="iconfont icon-rmb">89</span><span class="num">45人已购买</span>
</div>
</div>
</li>
</ul>
</div>
</main>
<!-- 底部 -->
<footer>
<div class="item active">
<a href="" class="iconfont icon-shejiaotubiao-44"></a>
</div>
<div class="item">
<a href="" class="iconfont icon-gouwuche"></a>
<a href="">购物车</a>
</div>
<div class="item">
<a href="" class="iconfont icon-wodetaobao"></a>
<a href="">我的淘宝</a>
</div>
</footer>
</body>
</html>
/* 样式重置 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* 链接 */
a {
text-decoration: none;
color: #555;
}
/* 列表 */
li {
list-style: none;
}
:root {
font-size: calc(100vw / 3.75);
}
body {
font-size: 0.12rem;
color: #333;
max-width: 750px;
min-width: 320px;
margin: auto;
background-color: #f4f4f4;
}
@media screen and (max-width: 320px) {
:root {
font-size: 85px;
}
}
@media screen and (min-width: 640px) {
:root {
font-size: 170px;
}
}
header {
position: relative;
}
header .top {
width: 100vw;
/* height: 50px; */
background-color: coral;
position: fixed;
top: 0;
left: 0;
right: 0;
display: grid;
grid-template-columns: 0.35rem 1fr;
padding: 0.1rem;
/* 调整层级 */
z-index: 99;
}
header .top .logo {
color: #fff;
font-size: 0.25rem;
}
header .top .search {
background-color: orangered;
color: #eee;
display: grid;
place-content: center;
border-radius: 0.06rem;
font-size: large;
}
/* baner图 */
header .slider {
height: 1.25rem;
/* 绝对定位 */
position: absolute;
top: 0.35rem;
}
header .slider img,
header .nav img {
width: 100%;
height: 100%;
}
/* 导航组 */
header .nav {
background-color: #fff;
/* 绝对定位 */
position: absolute;
top: calc(0.35rem + 1.25rem);
display: grid;
grid-template-columns: repeat(5, 1fr);
font-size: 0.11rem;
padding: 0.2rem 0.1rem;
}
header .nav .item {
display: grid;
place-items: center;
padding: 0 0.03rem;
}
header .nav .item a {
padding: 0 0.03rem;
}
footer {
width: 100vw;
height: 0.46rem;
background-color: white;
position: fixed;
left: 0;
right: 0;
bottom: 0;
display: grid;
grid-template-columns: repeat(3, 1fr);
place-items: center;
}
footer .item {
display: grid;
place-items: center;
}
footer .item .iconfont {
font-size: 0.2rem;
}
footer .item.active .iconfont {
font-size: 0.36rem;
color: coral;
}
main {
position: relative;
top: calc(0.37rem + 1.25rem + 1.5rem);
padding: 0.08rem;
}
main .list {
display: grid;
place-content: center;
}
main .list .title {
display: grid;
place-content: center;
place-items: center;
margin-top: 0.2rem;
}
main .list .title img {
width: 85%;
height: 85%;
}
/* 产品列表 */
main .list .unit {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 0.2rem;
font-size: 0.11rem;
padding: 0.2rem 0rem;
}
main .list .unit img {
width: 100%;
height: 100%;
}
main .list .unit .item {
display: grid;
place-items: center;
background-color: #fff;
border-radius: 0.06rem;
}
main .list .unit .item .detail {
display: grid;
grid-template-rows: 0.4rem 0.2rem;
gap: 0.1rem;
margin-bottom: 0.1rem;
}
main .list .unit .item .detail .desc {
font-size: small;
margin: 0.1rem;
}
main .list .unit .item .detail .price {
font-size: smaller;
}
main .list .unit .item .detail .price .iconfont {
color: red;
}
main .list .unit .item .detail .price .num {
margin-left: 0.08rem;
}
相关推荐
© 2020 asciim码
人生就是一场修行