Method: 1. Use the transform attribute with the scale() method to add the "transform:scale (x-axis magnification, y-axis magnification)" style to the image; 2. Use the width and height attributes to add the "transform:scale (x-axis magnification, y-axis magnification)" style to the image. Add the "width: width value; height: height value;" style.
The operating environment of this tutorial: Windows 10 system, CSS3&&HTML5 version, Dell G3 computer.
Method 1, use the transform attribute with the scale() method
The transform attribute applies 2D to the element or 3D conversion. This property allows us to rotate, scale, move or tilt the element.
scale(x,y) defines 2D scaling transformation.
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> *{ margin:0 auto; } .img1{ background:pink; transform:scale(1.5,1.5); } </style> </head> <body> <img src="1115.08.png" class="img1" alt="How to use CSS3 to enlarge images" > <br><br> <img src="1115.08.png" class="img2" alt="How to use CSS3 to enlarge images" > </body> </html>
Output result:
##Method 2, using the width and height attributes
The two properties are used to set the width and height of the element respectively. 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> *{ margin:0 auto; } .img1{ width:300px; height:200px; } </style> </head> <body> <img src="1115.08.png" class="img1" alt="How to use CSS3 to enlarge images" > <br><br> <img src="1115.08.png" class="img2" alt="How to use CSS3 to enlarge images" > </body> </html>
css video tutorial)
The above is the detailed content of How to use CSS3 to enlarge images. For more information, please follow other related articles on the PHP Chinese website!