CSS参考手册
媒体查询 | Media Queries
宽度 | @media.width
可以使用width CSS @media媒体特性来应用基于viewport宽度(或页面框,用于分页媒体)的样式。
语法
该width
特征被指定为<length>
表示视口宽度的值。这是一个范围功能,也就是说,您也可以使用前缀min-width
和max-width
变量分别查询最小值和最大值。
例子
HTML
<div>Watch this element as you resize your viewport's width.</div>
CSS
/* Exact width */
@media (width: 360px) {
div {
color: red;
}
}
/* Minimum width */
@media (min-width: 35rem) {
div {
background: yellow;
}
}
/* Maximum width */
@media (max-width: 50rem) {
div {
border: 2px solid blue;
}
}
结果
规范
Specification |
Status |
Comment |
---|---|---|
Media Queries Level 4The definition of 'width' in that specification. |
Working Draft |
The value can now be negative, in which case it computes to false. |
Media QueriesThe definition of 'width' in that specification. |
Recommendation |
Initial definition. The value must be nonnegative. |
浏览器兼容性
Feature |
Chrome |
Firefox (Gecko) |
Internet Explorer |
Opera |
Safari |
---|---|---|---|---|---|
Basic support |
(Yes) |
(Yes) |
9.0 |
(Yes) |
(Yes) |
Feature |
Android |
Firefox Mobile (Gecko) |
IE Mobile |
Opera Mobile |
Safari Mobile |
---|---|---|---|---|---|
Basic support |
? |
? |
? |
? |
? |
媒体查询 | Media Queries相关

层叠样式表( Cascading Style Sheets )是一种用来表现 HTML 或 XML 等文件样式的计算机语言。CSS 不仅可以静态地修饰网页,还可以配合各种脚本语言动态地对网页各元素进行格式化。