Home  >  Article  >  Web Front-end  >  How to use CSS3 to enlarge images

How to use CSS3 to enlarge images

WBOY
WBOYOriginal
2022-03-29 17:28:564568browse

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.

How to use CSS3 to enlarge images

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

How to use CSS3 to achieve the magnification effect of images

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:

How to use CSS3 to enlarge images

##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>

Output result:

How to use CSS3 to enlarge images

(Learning video sharing:

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!

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