移动端布局
移动端模拟器
切换平台之后,一定要重新刷新浏览器
访问的网站的PC端和移动端是否用同一代码实现?
1.大一点的网站的PC端和移动端都是分开开发的,各有一套代码。
访问淘宝网 ->后端检测当前设备 ->如果是PC端 ->www.taobao.com
访问淘宝网 ->后端检测当前设备 ->如果是移动端 ->www.taobao.com域名重定向 -> h5.m.taobao.com
2.响应式布局:实现多端适配(用一套代码实现PC端和移动端),一般用于小型网站
Viewport视口
- 仅在移动端才有viewport视口这一概念
- 定义:浏览器显示页面内容的屏幕区域
- 分类:1. visual viewport (可视视口):固定大小,和屏幕大小相同,在上面
2. layout viewport (布局视口):可改变大小,在下面。默认大小为980px,可通过document.documentElement.clientWidth获取 - 现代网页需要将layout viewport设置成跟visual viewport等同大小,方便网页制作。
ViewPort设置
通过< meta>标签进行设置,name属性指定viewport值,content属性进行视口配置。
<meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
一般都会设置下user-scalable=no
针对苹果X(底部有功能键,浏览器默认不覆盖)还有一个属性 viewport-fit=cover,这时浏览器会覆盖功能键,提高用户体验。
移动端适配方案
1. 流式布局(百分比布局)
代表网站:优酷、百度、天猫、腾讯
实现原理:不改变元素大小,适配通过改变元素之间的间距
流式布局原则
- 文字自适应到端点后折行(例:在窄设备下显示3行,在宽设备下显示2行)
- 对于元素,间距改变
- 图片等比缩放(选择大一点的原始图片,然后进行缩放,保证图片质量)
优点:大屏幕下显示更多的内容
缺点:宽屏下比例会有些不协调
实战
<link rel="stylesheet" href="./iconfont/iconfont.css">
<style>
*{
margin:0; padding:0;}
ul{
list-style: none;}
img{
display: block;}
a{
text-decoration: none; color:#555555;}
header{
height:45px; background:#00b38a; text-align:center;line-height:45px; font-size:20px; color:white;}
.login{
height: 43px; display: flex; justify-content: space-between; align-items:center; font-size:14px; }
.login p{
margin-left:16px; color:#555555;}
.login div{
width:84px; height:30px; background:#f5f5f5; margin-right:15px; text-align: center; line-height:30px; border-radius:15px; }
.login div a{
display:block; width:100%; height:100%; color:#17b994;}
.list li{
height:90px; border-top:1px #e8e8e8 solid; display:flex; align-items: center; }
.list .list_img{
width:60px; height:60px; margin:0 10px 0 14px;}
.list .list_img img{
width:100%;}
.list .list_info{
flex:1;}
.list .list_info h2{
font-size: 18px;}
.list .list_info p:first-of-type{
font-size: 14px; display:flex; justify-content: space-between; margin-top:4px;}
.list .list_info p:first-of-type span:last-of-type{
margin-right:14px; color:#17b994;}
.list .list_info p:last-of-type{
font-size: 12px; color:#888888; margin-top:8px;}
.more{
height:50px; background:#fafafa; border-top:1px solid #e8e8e8; text-align: center; line-height: 50px;}
.more a{
display:block; width:100%; height:100%;}
footer{
height:115px; text-align:center; font-size:12px; line-height:22px; padding-top:27px; box-sizing: border-box; margin-bottom:45px;}
.tabbar{
width:100%; height:45px; border-top:1px solid #e8e8e8; display:flex; position:fixed; bottom:0; background:#f6f6f6; font-size:18px; color:#c2cfcc;}
.tabbar i{
font-size:22px; position:relative; top:1px;}
.tabbar div{
flex:1; text-align: center; line-height: 45px;}
.tabbar .active{
background:#e7f3f0; color:#00b38a;}
</style>
<header>拉勾网</header>
<section class="login">
<p>10秒钟定制职位</p>