两种方式,一种是直接在link中判断设备的尺寸,然后引用不同的css文件:
|
1
|
<link rel="stylesheet" type="text/css" href="styleA.css" media="screen and (min-width: 400px)"> |
意思是当屏幕的宽度大于等于400px的时候,应用styleA.css
在media属性里:
|
1
|
<link rel="stylesheet" type="text/css" href="styleB.css" media="screen and (min-width: 600px) and (max-width: 800px)"> |
意思是当屏幕的宽度大于600小于800时,应用styleB.css
另一种方式,即是直接写在<style>标签里:
|
1
2
3
4
5
|
@media screen and (max-width: 600px) { /*当屏幕尺寸小于600px时,应用下面的CSS样式*/ .class { background: #ccc; }} |
写法是前面加@media,其它跟link里的media属性相同。
Max Width
下面的样式会在可视区域的宽度小于 600px 的时候被应用。
|
1
2
3
4
5
6
|
@media screen and (max-width: 600px) { .class { background: #fff; 你的样式 }} |
Min Width
下面的样式会在可视区域的宽度大于 900px 的时候被应用。
|
1
2
3
4
5
|
@media screen and (min-width: 900px) { .class { background: #fff; }} |
Multiple Media Queries
你还可以使用过个匹配条件,下面的样式会在可视区域的宽度在 600px 和 900px 之间的时候被应用。
|
1
2
3
4
5
|
@media screen and (min-width: 600px) and (max-width: 900px) { .class { background: #fff; }} |
原文:http://www.cnblogs.com/ada-zheng/p/4015142.html