响应式布局css
媒体查询css3
经常使用写法web
@media screen and (min-width: 768){}面试
#box { width: 200px; height: 200px; background-color: pink; } /* 媒体选择器 */ /* <= 768 */ @media screen and (max-width: 768px){ #box { background-color: red; } } /* 768 < ? < 1024 768 显示blue, 由于覆盖操做 */ @media screen and (min-width: 768px) and (max-width: 1024px){ #box { background-color: blue; } }
媒体选择器 必须写在正常样式以后,避免被覆盖编程
媒体查询 是 css3 提出来的,须要处理 +only 旧版本兼容浏览器
@media only screen and (max-width: 768px){}sass
取反 not网络
@media not screen and (width: 768px){ /* 不是 768 时的样式 */ }less
#box { width: 100px; height: 100px; } /* 打印模式下,出现边框 */ @media print and (min-width: 10px) { #box { border: 2px solid black; } }
在 PC 端,就是 PC分辨率(不监控 resize)布局
在移动端,表示 独立像素
像素比 可加 max min 前缀 兼容 2.1 2.2 之类的设备
portrait 竖屏
landscape 横屏
媒体选择器
<link rel="stylesheet" type="text/css" href="./css/index.css" media="print"> /* css2 提出来的,在打印模式下采用的样式 */
2x 图 3x 图
在保证不一样设备完美显示图片的前提下,节约网络带宽
less 编写媒体查询
less → sass → stylus
面试题: css 预编译语言 less 的优点
嵌套编程,层次感,结构鲜明
能够定义变量,混合 maxin