移动端特点
移动端和PC端网页不同点


谷歌模拟器

分辨率





视口





二倍图




百分比布局

<!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> <style> * { margin: 0; padding: 0; } li { list-style: none; } .toolbar { position: fixed; left: 0; bottom: 0; /* 百分比布局 流式布局 */ width: 100%; height: 50px; background-color: pink; border-top: 1px solid #ccc; } .toolbar li img { height: 100%; } .toolbar li { float: left; width: 20%; height: 50px; } </style> </head> <body> <div class="toolbar"> <ul> <li> <a href="#"><img src="./images/index.png" alt=""></a> </li> <li> <a href="#"><img src="./images/classify.png" alt=""></a> </li> <li> <a href="#"><img src="./images/jd.png" alt=""></a> </li> <li> <a href="#"><img src="./images/car.png" alt=""></a> </li> <li> <a href="#"><img src="./images/login.png" alt=""></a> </li> </ul> </div> </body> </html>
Flex布局


<!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>体验flex布局</title> <style> * { margin: 0; padding: 0; } .box { display: flex; justify-content: space-between; /* height: 200px; */ border: 1px solid #000; } .box div { /* float: left; margin: 10px; */ width: 100px; height: 100px; background-color: pink; } </style> </head> <body> <div class="box"> <div>1</div> <div>2</div> <div>3</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"> <title>体验flex布局</title> <style> * { margin: 0; padding: 0; } .box { /* 视觉效果: 子级一行排列/水平排列 */ /* 水平排列: 默认主轴在水平, 弹性盒子都是沿着主轴排列 */ display: flex; height: 200px; border: 1px solid #000; } .box div { width: 100px; height: 100px; background-color: pink; } </style> </head> <body> <div class="box"> <div>1</div> <div>2</div> <div>3</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"> <title>主轴对齐方式</title> <style> * { margin: 0; padding: 0; } .box { display: flex; /* 居中 */ justify-content: center; /* 间距在弹性盒子(子级)之间 */ justify-content: space-between; /* 所有地方的间距都相等 */ justify-content: space-evenly; /* 间距加在子级的两侧 */ /* 视觉效果: 子级之间的距离是父级两头距离的2倍 */ justify-content: space-around; height: 200px; margin: auto; border: 1px solid #000; } .box div { width: 100px; height: 100px; background-color: pink; } </style> </head> <body> <div class="box"> <div>1</div> <div>2</div> <div>3</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"> <title>侧轴对齐方式</title> <style> * { margin: 0; padding: 0; } .box { display: flex; /* 居中 */ /* align-items: center; */ /* 拉伸,默认值(现有状态,测试的时候去掉子级的高度) */ /* align-items: stretch; */ height: 300px; margin: auto; border: 1px solid #000; } .box div { /* width: 100px; */ /* height: 100px; */ background-color: pink; } /* 单独设置某个弹性盒子的侧轴对齐方式 */ .box div:nth-child(2) { align-self: center; } </style> </head> <body> <div class="box"> <div>1111</div> <div>2</div> <div>3</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"> <title>Document</title> <style> * { margin: 0; padding: 0; } .box { display: flex; height: 300px; border: 1px solid #000; } .box div { height: 200px; margin: 0 20px; background-color: pink; } .box div:nth-child(1) { width: 50px; } .box div:nth-child(2) { /* 占用父级剩余尺寸的份数 */ flex: 3; } .box div:nth-child(3) { flex: 1; } </style> </head> <body> <div class="box"> <div>1</div> <div>2</div> <div>3</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"> <title>确认订单</title> <link rel="stylesheet" href="./lib/iconfont/iconfont.css"> <link rel="stylesheet" href="./css/base.css"> <link rel="stylesheet" href="./css/orders.css"> </head> <body> <!-- 主体内容: 滑动查看 --> <div class="main"> <!-- 用户信息 --> <div class="pannel user_msg"> <div class="location"> <i class="iconfont icon-location"></i> </div> <div class="user"> <div class="top"> <h5>林丽</h5> <p>18500667882</p> </div> <div class="bottom">北京市 海淀区 中关村软件园 信息科技大厦1号 楼410# </div> </div> <div class="more"> <i class="iconfont icon-more"></i> </div> </div> <!-- 用户信息 --> </div> <!-- 主体内容: 滑动查看 --> <!-- 底部支付: 固定定位 --> <div class="pay"> <div class="left"> 合计: <span class="red">¥<i>266.00</i></span> </div> <div class="right"> <a href="#">去支付</a> </div> </div> <!-- 底部支付: 固定定位 --> </body> </html>
body {
background-color: #f7f7f8;
}
/* 公共样式 */
.red {
color: #cf4444;
}
.pannel {
margin-bottom: 10px;
background-color: #fff;
border-radius: 5px;
}
/* 主体内容 */
.main {
/* 80px: 为了内容不被底部区域盖住 */
padding: 12px 11px 80px;
}
/* 用户信息 */
.user_msg {
display: flex;
align-items: center;
padding: 15px 0 15px 11px;
}
.user_msg .location {
width: 30px;
height: 30px;
margin-right: 10px;
background-image: linear-gradient(90deg,
#6fc2aa 5%,
#54b196 100%);
border-radius: 50%;
text-align: center;
line-height: 30px;
color: #fff;
}
.user_msg .user {
flex: 1;
}
.user_msg .user .top {
display: flex;
}
.user_msg .user .top h5 {
width: 55px;
font-size: 15px;
font-weight: 400;
}
.user_msg .user .top p {
font-size: 13px;
}
.user_msg .user .bottom {
margin-top: 5px;
font-size: 12px;
}
.user_msg .more {
width: 44px;
height: 44px;
/* background-color: pink; */
text-align: center;
line-height: 44px;
color: #808080;
}
/* 主体内容 */
/* 底部支付 */
.pay {
position: fixed;
left: 0;
bottom: 0;
display: flex;
/* 主轴对齐方式 */
justify-content: space-between;
/* 侧轴对齐方式 */
align-items: center;
width: 100%;
height: 80px;
padding: 0 11px;
/* background-color: pink; */
border-top: 1px solid #ededed;
}
.pay .left {
font-size: 12px;
}
.pay .left i {
font-size: 20px;
}
.pay .right a {
display: block;
width: 90px;
height: 35px;
background-image: linear-gradient(90deg,
#6fc2aa 5%,
#54b196 100%);
border-radius: 3px;
text-align: center;
line-height: 35px;
font-size: 13px;
color: #fff;
}
/* 底部支付 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font: 16px/1.5 sans-serif;
color: #333;
background-color: #fff;
}
li {
list-style: none;
}
em,
i {
font-style: normal;
}
a {
text-decoration: none;
color: #333;
}
a:hover {
color: #5eb69c;
}
img {
width: 100%;
vertical-align: middle;
}
input {
padding: 0;
border: none;
outline: none;
color: #333;
}
button {
cursor: pointer;
}
/* 清除浮动 */
.clearfix:before,
.clearfix:after {
content: '';
display: table;
}
.clearfix:after {
clear: both;
}
.clearfix {
*zoom: 1;
}
ps:部分内容来自于互联网整理,如有侵权请联系我们,我们会在看到通知后24小时内做出处理。
posted on
浙公网安备 33010602011771号