日期:2014-05-16  浏览次数:20558 次

CSS3 之媒体查询Media Query

  Media Queries是CSS3有关媒体查询的属性,有了CSS3 之媒体查询Media Queries就可以进行媒体查询,针对每个不同的媒体进行不同的样式编写。传说中的Web响应式布局就可以毫无压力的做出来了。下面我们就一起来看看CSS3 之媒体查询Media Queries的相关知识吧。

 

  一、Media Query之引入方法


  1、外部引用

 <link rel="stylesheet" type="text/css" href="../css/print.css" media="print" />

  2、@media引入

@media screen{
     选择器{
	属性:属性值;
     }
   }

  3、xml方式引入

<?xml-stylesheet rel="stylesheet" media="screen" href="css/style.css" ?>

  4、@import方式引入

@import url("css/reset.css") screen;
@import url("css/print.css") print;

      

  二、Media Query的Media中的值

梦龙小站


  三、Media Query之兼容情况

梦龙小站


  四、Media Query之实例


  1、最大宽度Max Width——当屏幕小于或等于600px时,将采用small.css样式来渲染Web页面

<link rel="stylesheet" media="screen and (max-width:600px)" href="small.css" type="text/css" />

  2、最小宽度Min Width——当屏幕大于或等于900px时,将采用big.css样式来渲染Web页面

<link rel="stylesheet" media="screen and (min-width:900px)" href="big.css" type="text/css"  />

  3、多个Media Queries——当屏幕在600px-900px之间时采用style.css样式来渲染web页面

<link rel="stylesheet" media="screen and (min-width:600px) and (max-width:900px)" href="style.css" type="text/css" />

  4、设备屏幕的输出宽度Device Width——iphone.css样式适用于最大设备宽度为480px,比如说iPhone上的显示,这里的max-device-width所指的是设备的实际分辨率,也就是指可视面积分辨率

<link rel="stylesheet" media="screen and (max-device-width: 480px)" href="iphone.css" type="text/css" />

  5、iPhone4

<link rel="stylesheet" media="only screen and (-webkit-min-device-pixel-ratio: 2)" type="text/css" href="iphone4.css" />

  6、iPad——在纵向(portrait)时采用portrait.css来渲染页面;在横向(landscape)时采用landscape.css来渲染页面


<link rel="stylesheet" media="all and (orientation:portrait)" href="portrait.css" type="text/css" /> 
<link rel="stylesheet" media="all and (orientation:landscape)" href="landscape.css"  type="text/css" />

  7、Android

<!--240px的宽度-->
  <link rel="stylesheet" media=