Home >Web Front-end >CSS Tutorial >How to set image size in css

How to set image size in css

青灯夜游
青灯夜游Original
2021-04-13 18:50:5828703browse

In CSS, you can use the width and height attributes to set the image size; you only need to set the "width: value; height: value;" style for the img image element. The width and height attributes can set the width and height of the element's content area, excluding padding, borders, or margins.

How to set image size in css

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

In css, you can use the width and height attributes to set the image size.

Example:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title></title>
  <style>
  .a{
    width: 200px;
    height: 200px;
  }
  .b{
    width: 200px;
    height: 100px;
  }
  </style>
</head>

<body>
<img src="img/1.jpg" alt="" class="a">
<img src="img/1.jpg" alt="" class="b">
</body>

</html>

Rendering:

How to set image size in css

##Description:

The width attribute sets the width of the element, and the height attribute sets the height of the element.

The width and height attributes define the width and height of the element's content area, excluding padding, borders, or margins; padding, borders, and margins can be added outside the content area.

Attribute value:

ValueDescriptionautodefault. The browser will calculate the actual height. Use px, cm and other units to define the height. Based on the percentage height of the block-level object that contains it. inheritSpecifies that the value of the height attribute should be inherited from the parent element.
length
%
(Learning video sharing:

css video tutorial)

The above is the detailed content of How to set image size in css. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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