Home >Web Front-end >CSS Tutorial >How to set image size in css
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.
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:
##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:Description | |
---|---|
default. The browser will calculate the actual height. | |
length | Use px, cm and other units to define the height.|
% | Based on the percentage height of the block-level object that contains it.|
Specifies that the value of the height attribute should be inherited from the parent element. |
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!