Home  >  Article  >  Web Front-end  >  Use of html img tag

Use of html img tag

韦小宝
韦小宝Original
2017-12-02 10:26:273448browse

This article explains in detail the various functions of the picture tag in html. Pictures are definitely indispensable in a html page, The img tag of html is also very simple and easy to master. Let’s take a look!

img displays this map uses a relative path such as:

<img src="./imgs/002.jpg">

Development tips: In actual development, it will generally be in the project directory Create an imgs folder and put all the image resources in it to facilitate image calling during development. As shown above, ./imgs is the directory where the image is found, and /002.jpg is the image to be selected.

img displays web page images using absolute paths, such as:

<img src="https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png"/>

There are many attributes to choose from under img:

1. alt indicates the display content when the image is loaded incorrectly, so that visitors can know the purpose of the image.

For example:

<img src="./imgs/001.jpg12" alt="logo">

The displayed result is:

means that this picture is a logo picture.

2. align indicates the position where the image is aligned in the text.

top is aligned at the top, bottom is aligned at the bottom, and middle is aligned in the middle. Defaults to bottom alignment.

Two suspension effects: the left image floats to the left of the text, and the right image floats to the right of the text.

3. Change the size of the picture through width and height

The code demonstration of 2 and 3 is as follows

<p>一张百度logo<img src="./imgs/001.jpg" width="100"/></p>
<p>一张百度logo<img src="./imgs/001.jpg" align="top" width="100"/></p>
<p>一张logo<img src="./imgs/002.jpg" align="bottom" width="100"></p>
<p>百度logo<img src="./imgs/002.jpg" align="middle" width="100"></p>
<p>百度logo<img src="./imgs/002.jpg" align="left" width="100"></p>
<p>百度logo<img src="./imgs/002.jpg" align="right" width="100"></p>

The pictures are all under relative paths Local picture

4. Click the picture to open another link


<p>点击图片打开链接 <a href="page1.html" title="点击进入page1界面"> <img src="./imgs/001.jpg" alt="logo" width="200px" align="middle"/></a></p>

where page1.html is Another html document, the code is as follows:

<html>
<head>
    <title>page1界面</title>
</head>
<body>
    <p>我是page1</p>
</body>
</html>


Clicking on the image will open page1.html.

5. Image mapping

<img src="page.jpg" border="0" usemap="#page" alt="pages" />
<map name="page" id="page">
    <area shape="circle" coords="180,139,14" href ="page1.html" alt="page1" />
    <area shape="circle" coords="129,161,10" href ="page2.html" alt="page2" />
</map>

area and map are used together, and area is under the map tag. The usemap of img points to the name of the map. Click on different positions of the picture to enter two different links, page1 or page2.

The above is all about the use of html img tags. I hope it will be helpful to everyone.

Related recommendations:

Detailed graphic explanation of the difference between alt and title in the img attribute

#html in the a1f02c36ba31691bcfe87b2722de723b tag detailed explanation on creating image mapping

Why not use the img tag to control the image size in html?

The above is the detailed content of Use of html img tag. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn