In CSS, you can use the width and height attributes to set the size of the img element image. The width attribute is used to set the width value of the element, and the height attribute is used to set the height value of the element. The syntax is "img element { width: width value; height: height value;}".
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
How to set the image size of img using css
In css, you can use the width and height attributes to set the image size of img, example As follows:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>123</title> <style type="text/css"> .tupian{ width:150px; height:150px; } </style> </head> <body> <img src="1115.08.png" class="tupian" alt="How to set the image size of img using css" > <p>上面是设置了大小,下面没设置大小</p> <img src="1115.08.png" alt="How to set the image size of img using css" > </body> </html>
Output result:
In the above example, the width and height attributes are set at the same time. If you want to achieve equal scaling, you only need to set One attribute will do. The example is as follows:
When only the width:150px; style is added, the output result is:
When only the height:150px; style is added, the output result is:
(Learning video sharing: css video tutorial)
The above is the detailed content of How to set the image size of img using css. For more information, please follow other related articles on the PHP Chinese website!