แอตทริบิวต์สื่อ HTML
ความหมายและการใช้งาน
แอตทริบิวต์media
ระบุสื่อ/อุปกรณ์ที่เอกสารที่เชื่อมโยงได้รับการปรับให้เหมาะสม
แอตทริบิวต์นี้ใช้เพื่อระบุว่า URL เป้าหมายได้รับการออกแบบสำหรับอุปกรณ์พิเศษ (เช่น iPhone) คำพูด หรือสื่อสิ่งพิมพ์
คุณลักษณะนี้สามารถรับค่าได้หลายค่า
นำไปใช้กับ
สามารถใช้ แอตทริบิวต์media
กับองค์ประกอบต่อไปนี้:
องค์ประกอบ | คุณลักษณะ |
---|---|
<a> | สื่อ |
<พื้นที่> | สื่อ |
<link> | สื่อ |
<translation> | สื่อ |
<style> | สื่อ |
ตัวอย่าง
ตัวอย่าง
ลิงก์ที่มีแอตทริบิวต์สื่อ:
<a href="att_a_media.asp?output=print"
media="print and (resolution:300dpi)">
Open media attribute page for print.</a>
ตัวอย่างพื้นที่
แผนผังรูปภาพพร้อมพื้นที่ที่สามารถคลิกได้:
<img src="planets.gif" width="145" height="126" alt="Planets" usemap="#planetmap">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" alt="Sun"
href="sun.htm" media="screen and (min-color-index:256)">
</map>
ตัวอย่างลิงค์
สไตล์ชีตที่แตกต่างกันสองแบบสำหรับสื่อสองประเภทที่แตกต่างกัน (หน้าจอและการพิมพ์):
<head>
<link rel="stylesheet" type="text/css" href="theme.css">
<link rel="stylesheet" type="text/css" href="print.css" media="print">
</head>
ตัวอย่างที่มา
การใช้แอตทริบิวต์สื่อ:
<source src="movie.ogg" type="video/ogg"
media="screen and (min-width:320px)">
ตัวอย่างสไตล์
ระบุรูปแบบที่จะใช้สำหรับการพิมพ์:
<style media="print">
h1 {color:#000000;}
p {color:#000000;}
body {background-color:#FFFFFF;}
</style>
รองรับเบราว์เซอร์
แอตทริบิวต์media
มีการสนับสนุนเบราว์เซอร์ต่อไปนี้สำหรับแต่ละองค์ประกอบ:
Element | |||||
---|---|---|---|---|---|
a | Yes | Yes | Yes | Yes | Yes |
area | Yes | Yes | Yes | Yes | Yes |
link | Yes | Yes | Yes | Yes | Yes |
source | Not supported | Not supported | Not supported | Not supported | Not supported |
style | Yes | Yes | Yes | Yes | Yes |