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.
The operating environment of this article: windows7 system, HTML5 version, DELL G3 computer
htmlHow to change the picture size?
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.
<img src="/i/ct_1px.gif" style="max-width:90%" height="30px" / alt="How to change image size in html" >
This is the effect of the above HTML. This color bar is made from an image with only one pixel:
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!