css3媒体查询

  1. 语法结构及用法:
    @media 设备名 only (选取条件) not (选取条件) and(设备选取条件),设备二{sRules}
  2. 实际应用一 判断设备横竖屏:
/* 这是匹配竖屏的状态,竖屏时的css代码 */@media all and (orientation :portrait){}  ```
3. 实际应用二 判断设备类型:
```@media X and (min-width:200px){} X为设备类型》比如print/screen/TV等等```
4. 实际应用三 判断设备宽高:
```/* 宽度大于600px小于960之间时,隐藏footer结构 */@media all and (min-height:640px) and (max-height:960px){    footer{display:none;}} ```
5. 实际应用四 判断设备像素比:
```/* 像素比为1时,头部颜色为绿色 */     
.header { background:red;display:block;}或@media only screen and (-moz-min-device-pixel-ratio: 1), only screen and (-o-min-device-pixel-ratio: 1), only screen and (-webkit-min-device-pixel-ratio: 1), only screen and (min-device-pixel-ratio:1) {.header{background:green;} }```
``` /* 像素比为1.5时,头部背景为红色 */        
@media only screen and (-moz-min-device-pixel-ratio: 1.5), only screen and (-o-min-device-pixel-ratio: 1.5), only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min-device-pixel-ratio:1.5) {.header{background:red;} }```
```/*像素比为2,头部背景为蓝色 */    
@media only screen and (-moz-min-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2), only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio:2){.header{background:blue;} }  ```
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 能够让网站针对不同的浏览器和设备呈现不同显示效果 引入媒体查询 媒体查询写在CSS样式代码的最后,CSS是层叠样式...
    LYF闲闲闲闲阅读 499评论 0 3
  • -:Internet Explorer CSS :- SpecialPurpose _::selection, :...
    弥果阅读 1,327评论 0 1
  • 问题的由来 手机屏幕的分辨率差异很大。 iphone4:320×480 iphone6:375×667 H5 网页...
    尚山夏香阅读 2,453评论 0 1
  • 1、垂直对齐 如果你用CSS,则你会有困惑:我该怎么垂直对齐容器中的元素?现在,利用CSS3的Transform,...
    kiddings阅读 3,206评论 0 11
  • 不管黑夜的迷离 或是乌云的沉郁 我,仰望 即使星空一片沉寂 我了解 无论是非变换 无论沧海覆辙 那些依在 那心依在
    爱猫的旅行狗阅读 213评论 0 2