---
title: "移动设备样式之媒体查询HTML5<二>"
author: "喧嚣求静"
date: "2015-10-28T15:39:25Z"
tags: []
categories: ["移动开发"]
slug: "html5"
draft: false
lastmod: "2015-10-28T15:41:24Z"
id: 2252704
url: "https://913.iteye.com/blog/2252704"
---

关于media queries如何工作呢？

在传统网页布局向移动版本网页布局转换中起着最重要的作用，他能针对不同设备屏幕查询使用不同的样式

要实现media queries样式模块，需要在head标签内导放一个css样式文件，例如

使用media属性定义当前屏幕可视区域的宽度最大值是600[像素](http://cpro.baidu.com/cpro/ui/uijs.php?adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=18&is_app=0&jk=68471b21d8c6ee9&k=%CF%F1%CB%D8&k0=%CF%F1%CB%D8&kdi0=0&luki=1&n=10&p=baidu&q=69167098_cpr&rb=0&rs=1&seller_id=1&sid=e96e8c1db2718406&ssp2=1&stid=0&t=tpclicked3_hc&td=1836586&tu=u1836586&u=http%3A%2F%2Fwww.apk-doc.net%2Fh5%2Fmoblie-media-queryies-viewport2.html&urlid=0)时应用样式文件

&lt;link rel=”stylesheet” media=”screen and(max-width:600px)”  href=”small.css”/&gt;

在small.css样式文件内，需要定义media类型的样式，例如：

@media screen and (max-width:600px){

.demo{

background-color:#ccc;

}

}

media\_type设备可用类型

![](http://dl2.iteye.com/upload/attachment/0112/6658/4611d58f-5e90-3aa6-9a3f-2a4b1dbfb04a.png)  
   
![](http://dl2.iteye.com/upload/attachment/0112/6660/04628fda-2b20-3df0-bc54-d07ecfc301af.png)