Home >Web Front-end >CSS Tutorial >How to set the height and width of img element in css
How to set the height and width of the img element in css: 1. Use the width attribute to set the width of the img element. The syntax is "img{width:width value;}"; 2. Use the height attribute to set the height of the img element. , the syntax is "img{height:height value;}".
The operating environment of this tutorial: Windows 10 system, CSS3&&HTML5 version, Dell G3 computer.
How to set the height and width of the img element in css
In css, you can use the width and height attributes to set the width and height of the img element. The width attribute sets the width of the element, and the height attribute sets the height of the element.
The syntax is:
img{width:宽度值;height:高度值}
The example is 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>Document</title> <style> .img1{ width:100px; height:100px; } </style> </head> <body> <img src="1118.02.png" class="img1" alt="How to set the height and width of img element in css" ><br> 原始宽高:<br> <img src="1118.02.png" alt="How to set the height and width of img element in css" > </body> </html>
Output result:
(Learning video sharing:css video tutorial)
The above is the detailed content of How to set the height and width of img element in css. For more information, please follow other related articles on the PHP Chinese website!