How to change image size in html

藏色散人
Release: 2023-01-06 11:13:53
Original
26305 people have browsed it

htmlHow to change the image size: First create an HTML sample file; then create an image through img; finally set the size of the image through the height and width attributes.

How to change image size in html

The operating environment of this article: windows7 system, HTML5 version, DELL G3 computer

htmlHow to change the picture size?

How to change image size in html The height and width attributes of the tag set the dimensions of the image.

Tip: It is a good practice to specify height and width attributes for images. If these properties are set, space can be reserved for images when the page loads. Without these attributes, the browser cannot understand the dimensions of the image and reserve appropriate space for the image, so the layout of the page changes when the image loads. (This idea is explained in detail below).

Tip: Please do not scale the image through the height and width attributes. If the image is reduced via the height and width attributes, the user will have to download a larger image (even if the image looks small on the page). The correct approach is that before using the image on the web page, the image should be processed into the appropriate size through software.

Changing the image size - making a filled image

The height and width properties have a hidden property that one does not need to specify the actual size of the image, that is, these two The value can be larger or smaller than the actual size. The browser will automatically resize the image to fit within this reserved space. This method makes it easy to create thumbnails for large images, as well as enlarge very small images. But be warned: the browser still has to download the entire file, regardless of its final display size, and the image will be distorted if its original width and height ratio is not maintained.

Another technique using the height and width attributes is to make it very easy to fill the page area, while also improving the performance of the document. Imagine if you wanted to place a colored horizontal bar in your document. You don't need to create a full-sized image; instead, you create an image that is 1 pixel wide and 1 pixel tall, and give it the color you want to use. Then use the height and width properties to expand it to a larger size.

How to change image size in html
Copy after login

This is the effect of the above HTML. This color bar is made from an image with only one pixel:

How to change image size in html

The above is the detailed content of How to change image size in html. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!