【HTML element】How to embed images

【HTML element】How to embed images

The img element allows us to embed images in HTML documents.

To embed an image, you need to use the src and alt attributes, as shown below:

 < img src ="../img/example/img-map.jpg" alt ="Products Image" width ="580" height ="266" />

Display effect:

1 Embed an image in a hyperlink

A common usage of the img element is to create an image-based hyperlink in conjunction with the a element. The code is as follows:

XML/HTML CodeCopy content to clipboard
  1. <   href = "otherpage.html" >   
  2.      < img   src = "../img/example/img-map.jpg" ismap alt = "Products Image"   width = "580"   height = "266"   />   
  3. </ a >   

There is no difference in the way the browser displays this image. Therefore, it is important to provide users with a visual cue that a particular image represents a hyperlink. The specific approach can be to use CSS, and it would be better if it can be expressed in image content.

If you click on this image, the browser will navigate to the URL specified by the href attribute of the parent element a. Applying the ismap attribute to the img element creates a server-side partial responsive image, meaning that the location of clicks on the image is appended to the URL. For example, if the click is 8 pixels from the top of the image and 10 pixels from the left edge, the browser will navigate to the following URL:

XML/HTML CodeCopy content to clipboard
  1. https://yexiaochao.github.io/show4cnblogs/otherpage.html?10,8

The following code shows the contents of otherpage.html, which contains a simple script to display the coordinates of the click location:

XML/HTML CodeCopy content to clipboard
  1. < body >   
  2. < p > The X-coordinate is < b > < span   id = "xco" > ?? </ span > </ b > </ p >   
  3. < p > The Y-coordinate is < b > < span   id = "yco" > ?? </ span > </ b > </ p >   
  4. < script   type = "application/javascript" >   
  5. var coords = window .location.href.split('?')[1].split(',');
  6. document.getElementById("xco") .innerHTML = coords [0];
  7. document.getElementById("yco") .innerHTML = coords [1];
  8. </ script >   
  9. </ body >   

You can see the effect of mouse clicks:

A server-side partitioned response image usually means that the server will respond differently depending on the area the user clicks on the image, such as returning different response information. If you omit the ismap attribute on the img element, the coordinates of the mouse click will not be included in the request URL.

2 Create a client partition response map

We can create a client-side responsive map that allows the browser to navigate to different URLs by clicking on different areas of an image. This process does not need to be directed from a server, so elements are used to define the various areas on the image and the behavior they represent. The key element of the client-side partition response map is map. 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 user clicks on the image area represented by area. The following diagram introduces this category of properties, which are similar to corresponding properties seen on other elements.

The second category contains the more interesting attributes: shape and coords attributes. You can use these attributes to indicate individual areas of the image that the user can click. The shape and coords attributes work together. The meaning of the coords attribute depends on the value of the shape attribute, as shown in the following figure:

After introducing these elements, let's take an example, the code is as follows:

XML/HTML CodeCopy content to clipboard
  1. < body >   
  2.      < img   src = "../img/example/img-map.jpg" ismap alt = "Products Image"   usemap = "#mymap"   width = "580"   height = "266"   />   
  3.   
  4. < map   name = "mymap" >   
  5.      < area   href = "javascript:show_page(1)"   shape = "rect"   coords = "'34,60,196,230"   alt = "product 1"   />   
  6.      < area   href = "javascript:show_page(2)"   shape = "rect"   coords = "'210,60,370,230"   alt = "product 2"   />   
  7.      < area   href = "javascript:show_page(3)"   shape = "rect"   coords = "'383,60,545,230"   alt = "product 3"   />   
  8. </ map >   
  9.   
  10. < script   type = "application/javascript" >   
  11. function show_page(num){
  12. //Display the product through the dialog box, indicating the corresponding jump page
  13. alert("This is product "+num);
  14. }
  15. </ script >   
  16. </ body >   

Click the link to view the effect: http://yexiaochao.github.io/show4cnblogs/img-map.html

The display effect is the same, except that when you click on the corresponding product picture, the corresponding product name will pop up, indicating the product page you will jump to.

The above [HTML element] implementation method of embedding images is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

Original URL: http://www.cnblogs.com/luka/archive/2016/07/23/5580949.html

<<:  Detailed explanation of Linux remote management and sshd service verification knowledge points

>>:  Implementation of draggable rows and columns and selection column components based on el-table encapsulation

Recommend

How to create a swap partition file in Linux

Introduction to Swap Swap (i.e. swap partition) i...

Linux kernel device driver kernel debugging technical notes collation

/****************** * Kernel debugging technology...

CocosCreator implements skill cooling effect

CocosCreator realizes skill CD effect There are s...

Example code for converting Mysql query result set into JSON data

Mysql converts query result set into JSON data Pr...

Implementation method of Mysql tree recursive query

Preface For tree-structured data in the database,...

Detailed explanation of Jquery datagrid query

Table of contents Add code to the Tree item; 1. S...

The past two years with user experience

<br />It has been no more than two years sin...

Implementation of setting fixed IP when starting docker container

Network type after docker installation [root@insu...

How to use Celery and Docker to handle periodic tasks in Django

As you build and scale your Django applications, ...

Detailed explanation of non-parent-child component communication in Vue3

Table of contents First method App.vue Home.vue H...

Implementation of vue+drf+third-party sliding verification code access

Table of contents 1. Background 2. Verification p...

Example code for implementing the "plus sign" effect with CSS

To achieve the plus sign effect shown below: To a...

Thoughts on copy_{to, from}_user() in the Linux kernel

Table of contents 1. What is copy_{to,from}_user(...

Swiper.js plugin makes it super easy to implement carousel images

Swiper is a sliding special effects plug-in built...

A quick solution to the first login failure in mysql5.7.20

First, we will introduce how (1) MySQL 5.7 has a ...