Home > Web Front-end > Front-end Q&A > How to use CSS3 to enlarge images

How to use CSS3 to enlarge images

WBOY
Release: 2022-03-29 17:54:24
Original
4665 people have browsed it

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

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

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