最新的Web开发教程
 

HTML <link> media Attribute

<HTML <link>标签

两种不同的样式表两种不同的媒体类型(屏幕和打印):

<head>
<link rel="stylesheet" type="text/css" href="theme.css">
<link rel="stylesheet" type="text/css" href="print.css" media="print">
</head>
试一试»

定义和用法

media属性指定的介质/设备的目标资源的优化。

此属性大多与CSS样式表用于指定不同的媒体类型不同的风格。

media属性可以接受多个值。


浏览器支持

属性
media

HTML 4.01和HTML5之间的差异

media属性现在支持多个值。


句法

<link media="value">

可能的Operators

描述
and 指定AND运算符
not 指定NOT运算符
, 指定OR运算符

设备

描述
all 默认。 适用于所有设备
aural 语音合成器
braille 盲文反馈装置
handheld 手持设备(小屏幕,有限的带宽)
projection 投影机
print 打印预览模式/打印页面
screen 电脑屏幕
tty 使用固定宽字符网格的电传打字机和类似媒体
tv 电视类型设备(低分辨率,有限的滚动能力)

描述
width 指定目标的显示区域的宽度。
"min-""max-"可使用的前缀。
例如: media="screen and (min-width:500px)"
height 指定目标的显示区域的高度。
"min-""max-"可使用的前缀。
例如: media="screen and (max-height:700px)"
device-width 指定目标显示器/纸张的宽度。
"min-""max-"可使用的前缀。
例如: media="screen and (device-width:500px)"
device-height 指定目标显示器/纸张的高度。
"min-""max-"可使用的前缀。
例如: media="screen and (device-height:500px)"
orientation 指定目标显示/纸的方向。
可能的值: "portrait""landscape"
例如: media="all and (orientation: landscape)"
aspect-ratio 指定目标的显示区域的宽度/高度比。
"min-""max-"可使用的前缀。
例如: media="screen and (aspect-ratio:16/9)"
device-aspect-ratio 指定目标显示/纸的设备宽度/设备高度比。
"min-""max-"可使用的前缀。
例如: media="screen and (aspect-ratio:16/9)"
color 指定每个目标的显示颜色的位。
"min-""max-"可使用的前缀。
例如: media="screen and (color:3)"
color-index 指定颜色目标显示可以处理的数量。
"min-""max-"可使用的前缀。
例如: media="screen and (min-color-index:256)"
monochrome 指定在单色帧缓冲器每像素的位。
"min-""max-"可使用的前缀。
例如: media="screen and (monochrome:2)"
resolution 指定目标显示器/纸张的像素密度(DPI或DPCM)。
"min-""max-"可使用的前缀。
例如: media="print and (resolution:300dpi)"
scan 指定一个电视显示器的扫描方法。
可能的值是"progressive""interlace"
例如: media="tv and (scan:interlace)"
grid 指定是否输出设备是电网或位图。
可能的值是"1"为网格,和"0"否则。
例如: media="handheld and (grid:1)"

<HTML <link>标签