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 img element in css

WBOY
Release: 2021-12-09 18:45:08
Original
9542 people have browsed it

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;}".

How to set the height and width of img element in css

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:高度值}
Copy after login

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>
Copy after login

Output result:

How to set the height and width of img element in css

(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!

Related labels:
css
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 admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template