2 回答

TA贡献63条经验 获得超18个赞
学习媒体查询做的笔记。总结一下,借此复习一遍。嗯。
<link rel="stylesheet" href="" media="screen"> @mmdia all and (min-width:800px) and (orientation:landscape){ ... }
上面两个是媒体查询的例子
媒体查询就是对媒体类型和媒体属性表达式求值。如果为真应用样式,为假不应用样式。对于link标签的媒体查询,求值结果为假时样式表会被下载,只是样式不被应用。
媒体类型
all -- 所有设备。如没有only和not限定可以省略,省略不写时默认为all
print -- 打印机
screen -- 计算机屏幕
等等
and & not & only & 逗号 操作符
and -- 所有媒体属性表达式为真时,媒体查询结果才为真。
not -- 对媒体结果求值取反。如果有逗号操作符,其作用范围至逗号处为止
1.
@media not all and (min-width:800px){...}
等价于
@media not (all and (min-width:800px)){...}
而不是
@media (not all) and (min-width:800px){...}
2.
@media not screen and (color), print and (color)
等价于
@media (not (screen and (color))), print and (color)
only -- 防止不支持媒体查询的浏览器错误应用样式。
<link rel="stylesheet" href="" media="only screen and (color)" >
不支持媒体查询的浏览器会解析成media=only,只媒体类型没有only,所以不会被不支持媒体查询的浏览器应用样式。而如果不使用only
<link rel="stylesheet" href="" media="screen and (color)" >
不支持媒体查询的浏览器会解析成media=screen,媒体属性不会求值。从而错误地应用样式。
, -- 逗号相当于or(或者)
常用媒体属性
width : 可视宽度
height : 可视高度
device-width: 设备宽度
device-height: 设备高度
orientation: 方向
aspect-ratio: 宽高比
color: 颜色
device-aspect-ratio: 设备宽高比

TA贡献3593条经验 获得超1个赞
- 2 回答
- 0 关注
- 2410 浏览
相关问题推荐
添加回答
举报