Home > Article > Web Front-end > HTML5 - A closer look at embedded content
The img element allows us to embed images in HTML documents. The image is not loaded until the HTML markup has been processed! ! The
src attribute specifies the URL of the image to be embedded; the
alt attribute defines the alternative content of the img element (rendered when the image cannot be displayed).
The width and height attributes specify the size (in pixels) of the image represented by the img element. If this attribute is omitted, the browser does not know how much screen space to allow for the image. The result is that the browser must rely on the image file itself to determine its size and then relocate the on-screen content to accommodate it, resulting in Shake.
Example: Use img and a elements to create a server-side partitioned response graph
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>使用img和a元素创建服务器端的分区响应图</title></head><body><a href="otherpage.html"> <img src="../images/sport.jpg" ismap alt="奥运会运动项目" width="520px" height="131px"></a></body></html>
http://localhost:63342/html_test/public/embeddedContent_Chapter15/otherpage.html?466,39
Adding the ismap attribute creates a server-side partition response graph, and the URL address will contain the coordinates of the mouse click.
Create a client-side partition response graph and let the browser navigate to different URLs by clicking on different areas on an image.
The map element contains one or more area elements, each of which represents a clickable area on the image.
The attributes of the area element can be divided into two categories: the first category deals with the URL that the browser will navigate to after the image area represented by the area is clicked by the user; the second category Contains shape and coords attributes to indicate various image areas that the user can click.
Table area element attributes related to the target address
Attribute | Description |
---|---|
href | The URL that the browser should load when this area is clicked |
alt | Alternate content |
target | The browsing context that should be used to display the URL |
rel | Describes the relationship between the current document and the target document |
meida | Media applicable to this area |
hreflang | The language of the target document |
type | The MIME type of the target document |
The values of table shape and coords attributes
Attributes | coords value properties and meaning |
---|---|
rect | represents a rectangular area. The coords attribute must consist of four comma-separated integers (left, top, right, bottom) |
circle | represents a circular area. The coords attribute must consist of three integers separated by commas (the distance from the left edge to the center of the circle, the distance from the upper edge to the center of the circle, and the radius) |
poly | represents a polygon. The coords attribute must contain at least six integers separated by commas (each number represents a vertex of the polygon) |
default | The default area, which covers the entire sheet Picture |
Example: Creating a Partitioned Response Graph
<p> <img src="../images/sport.jpg" usemap="#sportmap" alt="Sport image"></p><map name="sportmap"> <area href="archery.html" shape="rect" coords="0,5,90,125" alt="射箭"> <area href="swimming.html" shape="rect" coords="120,5,250,125" alt="游泳"> <area href="weightlifting.html" shape="rect" coords="290,5,390,125" alt="举重"> <area href="hockey.html" shape="rect" coords="420,5,520,125" alt="曲棍球"> <area href="sport.html" shape="default" alt="运动"></map>
Note:
1. Add the usemap attribute to the img element; associate it with the map element.
2. There is no need to use the a element to display hyperlinks.
The iframe element allows us to embed another document in an existing HTML document.
Example: Using iframe elements
<header> <nav> <ul> <li> <a href="img_a.html" target="myframe">Img a Demo</a> </li> <li> <a href="img_map.html" target="myframe">Img map Demo</a> </li> </ul> </nav></header><iframe name="myframe" width="300" height="100"></iframe>
In the above example, an iframe element with the name attribute myframe is created, thus creating an iframe element with the name is the browsing context of myframe. This browsing context is then used in conjunction with the target attribute of other elements (specifically a, form, button, input, and base). In the example, the URL specified in the href attribute will be loaded into the iframe.
Other attributes of the table
Attributes | Description |
---|---|
src | Specify the URL that the iframe should load and display at the beginning |
srcdoc | Define a URL for inlining Displayed HTML document |
seamless | Display iframe content as if it were an integral part of the main HTML document (not supported by the browser) |
sandbox | Restrict HTML documents (not supported by the browser) |
object和embed元素最初都是作为扩展浏览器能力的一种方式,用于添加插件支持,而插件能够处理浏览器不直接支持的内容。
示例:嵌入视频
<embed src="https://www.youtube.com/embed/jItLiNKSCBg" width="560" height="349" allowfullscreen="true"><object data="https://www.youtube.com/embed/jItLiNKSCBg" width="560" height="349"> <param name="allowFullScreen" value="true"> <b>Sorry!</b>We can't display this content</object>
示例:用object元素嵌入一张图像
<object data="../images/sport.jpg" type="image/jpg"></object>
示例:用object元素创建一张客户端分区响应图
<header> <nav> <ul> <li> <a href="img_a.html" target="myframe">Img a Demo</a> </li> <li> <a href="img_map.html" target="myframe">Img map Demo</a> </li> </ul> </nav></header><object type="text/html" name="myframe" width="300" height="100"></object>
注意:chrome和Safari目前不支持用object元素创建客户端分区响应图
示例:用object元素创建浏览器上下文
<p> <object type="image/jpg" data="../images/sport.jpg" usemap="#sportmap"></object></p><map name="sportmap"> <area href="archery.html" shape="rect" coords="0,5,90,125" alt="射箭"> <area href="swimming.html" shape="rect" coords="120,5,250,125" alt="游泳"> <area href="weightlifting.html" shape="rect" coords="290,5,390,125" alt="举重"> <area href="hockey.html" shape="rect" coords="420,5,520,125" alt="曲棍球"> <area href="sport.html" shape="default" alt="运动"></map>
progress元素可以用来表现某项任务逐渐完成的过程。
value属性定义了当前的进度,它位于0和max属性的值所构成的范围之间。当max属性被省略时,范围是0至1。
示例:使用progress元素
<progress id="myprogress" value="10" max="100"></progress><p> <button type="button" value="30">30%</button> <button type="button" value="60">60%</button> <button type="button" value="90">90%</button></p><script> var buttons = document.getElementsByTagName("button"); var progress = document.getElementsByTagName("progress")[0]; for(var i = 0, len = buttons.length; i < len; i++){ buttons[i].onclick = function(e){ progress.value = e.target.value; // 千万不能通过 buttons[i].value 获取值 } }</script>
meter元素显示了某个范围内所有可能值中的一个。
min和max属性设定了可能值所处范围的边界,它们可以用浮点数表示。
meter元素的显示可以分为三个部分:过低、过高和最佳。
low属性设置一个值,在它之下的所有值都被认为是过低;
high属性设置一个值,在它之上的所有值都被认为是过高;
optimum属性则指定了“最佳”的值。
<meter id="mymeter" value="90" min="0" max="100" low="40" high="80" optimum="60"></meter><p> <button type="button" value="30">30</button> <button type="button" value="60">60</button> <button type="button" value="90">90</button></p><script> var buttons = document.getElementsByTagName("button"); var meter = document.getElementById("mymeter"); for(var i = 0, len = buttons.length; i < len; i++){ buttons[i].onclick = function(e){ meter.value = e.target.value; } }</script>
The above is the detailed content of HTML5 - A closer look at embedded content. For more information, please follow other related articles on the PHP Chinese website!