©
本文档使用
php中文网手册 发布
width:<length>
接受min/max前缀:是
<length>:用长度值来定义宽度。不允许负值
与盒模型width不同,媒体特性width的取值只能是<length>。
本特性接受min和max前缀,因此可以派生出min-width和max-width两个媒体特性。
简单列举几个应用示例:
@media screen and (width){ … }
@import url(example.css) screen and (width:800px);
<link media="screen and (min-width:400px) and (max-width:900px)" rel="stylesheet" href="example.css" />
<?xml-stylesheet media="not screen and (width:800px)" rel="stylesheet" href="example.css" ?>| Values | IE | Firefox | Chrome | Safari | Opera | iOS Safari | Android Browser | Android Chrome |
|---|---|---|---|---|---|---|---|---|
| Basic Support | 6.0-8.0 | 2.0-3.0 | 4.0-25.0#1 | 6.0#1 | 15.0+ | 6.0-6.1#1 | 2.1-4.3#1 | 18.0-24.0#1 |
| 9.0#1 #2 | 3.5-9.0#3 | 26.0+ | 6.1+ | 7.0+ | 4.4+ | 25.0+ | ||
| 10.0-11.0#1 | 10.0+ |
不支持嵌套媒体查询。
使用width作为媒体查询条件,是包含滚动条在内的
支持min-width但却无效。
<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
<meta charset="utf-8" />
<title>media features width_CSS参考手册_web前端开发参考手册系列</title>
<meta name="author" content="Joy Du(飘零雾雨), dooyoe@gmail.com, www.doyoe.com" />
<style>
@media all and (min-width:500px) and (max-width:1000px){
body{color:#f00;}
}
</style>
</head>
<body>
<div class="test">当页面可见宽度大于500px小于1000px时,本行文字显示为红色。试着调整你的viewport使得页面宽度介于这个区间以查看效果</div>
</body>
</html>
点击 "运行实例" 按钮查看在线实例