Home > Web Front-end > CSS Tutorial > How to set the image size of img using css

How to set the image size of img using css

WBOY
Release: 2021-11-29 15:40:35
Original
22341 people have browsed it

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

How to set the image size of img using css

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

Output result:

How to set the image size of img using css

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:

How to set the image size of img using css

When only the height:150px; style is added, the output result is:

How to set the image size of img using css

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

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