赞
踩
移动适配方案
检查 -> 切换到仿真设备 -> 刷新
手机型号 | 物理分辨率 | 逻辑分辨率 | 比例关系 |
---|---|---|---|
iPhone3GS | 320 * 480 | 320 * 480 | 1:1 |
iPhone4 | 640 * 960 | 320 * 480 | 2:1 |
iPhone5 | 640 * 1136 | 320 * 568 | 2:1 |
iPhone6/7/8 | 750 * 1334 | 375 * 667 | 2:1 |
iPhone6/7/8 Plus | 1080 * 1920 | 414 * 736 | 2.6:1 |
iPhone11Pro/X/XS | 1125 * 2436 | 375 * 812 | 3:1 |
iPhone11/XR | 828 * 1792 | 414 * 896 | 2:1 |
iPhone11 Pro Max/XS Max | 1242 * 2688 | 414 * 896 | 3:1 |
iPhone12 mini | 1080 * 2340 | 360 * 780 | 3:1 |
iPhone12/iPhone12 Pro | 1170 * 2532 | 390 * 844 | 3:1 |
iPhone12 Pro Max | 1284 * 2778 | 428 * 926 | 3:1 |
<!-- width=device-width : 视口宽度 = 设备宽度-->
<!-- initial-scale=1.0 : 缩放1倍(不缩放)-->
<!-- 视口标签 (会自动生成)-->
<!-- 视口标签:规定HTML的尺寸,让HTML的宽度 = 逻辑分辨率的宽度/设备的宽度 -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
概念:设计稿里面每个元素的尺寸的倍数
作用:防止图片在高分辨率屏幕下模糊失真
现阶段设计稿参考iPhone6/7/8,设备宽度375px产出设计稿
二倍图设计稿尺寸:750px
/* 1. 给HTML标签添加字号 */
html {
font-size:30px
}
/* 2. 使用rem单位书写尺寸 */
.box {
width: 5rem;
height: 3rem;
background-color: pink;
}
@media (媒体特性) {
选择器 {
CSS属性
}
}
<!-- 视口宽度320px,根字号为32px -->
@media (width: 320px) {
html {
font-size: 32px;
}
}
<body>
……
<!-- script:脚本 -->
<script src="./js/flexible.js"></script>
</body>
// flexible.js内容 (function flexible (window, document) { var docEl = document.documentElement var dpr = window.devicePixelRatio || 1 // adjust body font size function setBodyFontSize () { if (document.body) { document.body.style.fontSize = (12 * dpr) + 'px' } else { document.addEventListener('DOMContentLoaded', setBodyFontSize) } } setBodyFontSize(); // set 1rem = viewWidth / 10 function setRemUnit () { var rem = docEl.clientWidth / 10 docEl.style.fontSize = rem + 'px' } setRemUnit() // reset rem unit on page resize window.addEventListener('resize', setRemUnit) window.addEventListener('pageshow', function (e) { if (e.persisted) { setRemUnit() } }) // detect 0.5px supports if (dpr >= 2) { var fakeBody = document.createElement('body') var testElement = document.createElement('div') testElement.style.border = '.5px solid transparent' fakeBody.appendChild(testElement) docEl.appendChild(fakeBody) if (testElement.offsetHeight === 1) { docEl.classList.add('hairlines') } docEl.removeChild(fakeBody) } }(window, document))
工作中,书写代码的尺寸要参照设计稿尺寸——rem单位尺寸
目标:计算68px是多少个rem? (设计稿适配375px视口)
N * 375 = 68
N = 68 / 375
/* 68px*29px盒子 */
div {
width: 1.813rem;
height: 0.773rem;
background-color: pink;
}
width: (100px / 2);
width: 68px ./ 37.5rem; //如表达式有多个单位,最终CSS里以第一个单位为准 此例为px
less 代码:
.父选择器 { //父级样式 .子选择器 { //子级样式 } } .father { color: red; .son { width: 100px; a { color: green; // & 表示的是当前选择器,代码写到谁的大括号里就表示谁 -> 不会生成后代 (类似于C++里的this) // 应用:配合hover伪类或者nth-child结构伪类使用 &:hover { color: blue; } } } }
自动生成的css代码:
.father {
color: red;
}
.father .son {
width: 100px;
}
.father .son a {
color: green;
}
.father .son a:hover {
color: blue;
}
/* 定义变量 */
@myColor: pink;
/* 使用变量 */
.box {
color: @myColor;
}
a {
color: @myColor;
}
@import "./base.less";
@import "./common";
// out: ./index.css
// out: ./css/
// out:false
/* vw 和 vh 是相对视口宽高计算结果,可以直接实现移动端适配效果 */
/* .box {
width: 50vw;
height: 30vw;
background-color: pink;
} */
.box {
width: 50vh;
height: 30vh;
background-color: pink;
}
解决方案:媒体查询、Bootstrap
@media (媒体特性) { 选择器 { 样式 } } @media (max-width: 768px) { html { background-color: green; } } @media (min-width: 1200px) { html { background-color: pink; } }
需求:
提示:
/* 默认网页背景色是灰色 */ body { background-color: #ccc; } /* 屏幕宽度大于等于 768px, 网页背景色是粉色 */ @media (min-width: 768px){ body { background-color: pink; } } /* 屏幕宽度大于等于 992px, 网页背景色是绿色 */ @media (min-width: 992px){ body { background-color: green; } } /* 屏幕宽度大于等于 1200px,网页背景色是skyblue */ @media (min-width: 1200px){ body { background-color: blue; } }
关键词 媒体类型 and (媒体特性) { CSS 代码 }
关键词/逻辑操作符
|
|
|
---|---|---|
屏幕 | screen | 带屏幕的设备 |
打印预览 | 打印预览模式 | |
阅读器 | speech | 屏幕阅读模式 |
不区分类型 | all | 默认值,包括以上3种情形 |
|
|
|
---|---|---|
视口的宽和高 | width、 height | 数值 |
视口的最大宽和高 | max-width、max-height | 数值 |
视口的最小宽和高 | min-width、min-height | 数值 |
屏幕方向 | orientation | portrait:竖屏 landscape: 横屏 |
逻辑符、媒体类型 可以省略,小括号必须要有,否则不生效
<link rel="stylesheet" media="逻辑符 媒体类型 and (媒体特性)" href="xx.css">
<!-- 视口宽度 小于等于768px 网页背景为粉色 -->
<link rel="stylesheet" media="(max-width: 768px)"href="pink.css">
<!-- 视口宽度 大于等于1200px 网页背景为绿色 -->
<link rel="stylesheet" media="(min-width: 1200px)"href="green.css">
简介:Bootstrap是由Twitter公司开发维护的前端UI框架,它提供了大量编写好的CSS样式,允许开发者结合一定HTML结构及JavaScript,快速编写功能完善的网页及常见交互效果。
中文文档: https://v5.bootcss.com/docs/5.3/getting-started/introduction/
下载步骤:Bootstarp V5中文文档 → 进入中文文档 → 下载 → 下载Bootstrap生产文件
github无法连接:
140.82.121.4 https://github.com/
使用步骤:
<link rel="stylesheet" href="./Bootstrap/css/bootstrap.min.css">
<div class="container">测试</div>
栅格化是指将整个网页的宽度分成12等份,每个盒子占用的对应的份数
例如:一行排4个盒子,则每个盒子占 3份 即可(12/4 = 3)
|
|
|
---|---|---|
Extra small | None | <576px |
Small | sm | ≥576px |
Medium | md | ≥768px |
Large | lg | ≥992px |
Extra | xl | ≥1200px |
Extra extra large | xx1 | ≥1400px |
Bootstrap5中,栅格系统划分了6个响应区间
xs <576px | sm ≥576px | md ≥768px | lg ≥992px | xl ≥1200px | xxl ≥1400px | |
---|---|---|---|---|---|---|
Container max-width | None(auto) | 540px | 720px | 960px | 1140px | 1320px |
Class prefix | .col- | .col-sm- | .col-md- | .col-lg- | .col-xl- | .col-xxl- |
常用布局类
<!--
视口宽度大于等于1200px,一行排4个盒子
视口宽度大于等于768px,一行排2个盒子
视口宽度大于等于576px,一行排1个盒子
-->
<!-- 版心 → row → 子级 -->
<div class="container">
<div class="row">
<div class="col-xl-3 col-md-6 col-sm-12">1</div>
<div class="col-xl-3 col-md-6 col-sm-12">2</div>
<div class="col-xl-3 col-md-6 col-sm-12">3</div>
<div class="col-xl-3 col-md-6 col-sm-12">4</div>
</div>
</div>
代码提示插件:
中文文档: https://v5.bootcss.com/docs/5.3/getting-started/introduction/
Button类
官方文档:https://v5.bootcss.com/docs/components/buttons/
<button type="button" class="btn btn-primary">Primary</button>
<button type="button" class="btn btn-secondary">Secondary</button>
<button type="button" class="btn btn-success">Success</button>
<button type="button" class="btn btn-danger">Danger</button>
<button type="button" class="btn btn-warning">Warning</button>
<button type="button" class="btn btn-info">Info</button>
<button type="button" class="btn btn-light">Light</button>
<button type="button" class="btn btn-dark">Dark</button>
<button type="button" class="btn btn-link">Link</button>
表格类
官方文档:https://v5.bootcss.com/docs/content/tables/
更多类可参考官方中文文档
下载:
使用:
<i class="bi bi-android2"></i>
<!-- 使用时前面bi可省略 -->
<i class="bi-android2"></i>
HTML学习
Web移动端学习
JS基础学习
Web API学习
JS进阶学习
ajax学习
Node.js与Webpack学习
Git学习—学习中
vue学习—学习中
小程序学习—学习中
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。