Home Web Front-end Front-end Q&A How to change image size in html

How to change image size in html

May 18, 2021 am 11:56 AM
html

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.

<img  src="/static/imghw/default1.png"  data-src="/i/ct_1px.gif"  class="lazy"      style="max-width:90%" height="30px" / alt="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!

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 admin@php.cn

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

Nested Table in HTML

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Table Border in HTML

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

HTML margin-left

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

HTML Table Layout

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Moving Text in HTML

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

HTML Ordered List

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

How do you parse and process HTML/XML in PHP?

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

HTML onclick Button

See all articles