?
This document uses PHP Chinese website manual Release
width:<length>
接受min/max前綴:是
<length>:用長度值來定義寬度。不允許負值
與盒模型width不同,媒體特性width的取值只能是<length>。
本特性接受min和max前綴,因此可以派生出min-width和max-width兩個媒體特性。
簡單列舉幾個應(yīng)用示例:
@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作為媒體查詢條件,是包含滾動條在內(nèi)的
支持min-width但卻無效。
<!DOCTYPE html> <html lang="zh-cmn-Hans"> <head> <meta charset="utf-8" /> <title>media features width_CSS參考手冊_web前端開發(fā)參考手冊系列</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時,本行文字顯示為紅色。試著調(diào)整你的viewport使得頁面寬度介于這個區(qū)間以查看效果</div> </body> </html>
點擊 "運行實例" 按鈕查看在線實例