How to set css to hide overflow after image is enlarged

WBOY
Release: 2021-12-10 18:21:27
Original
4837 people have browsed it

Method: 1. Add the "transform:scale (horizontal scaling value, vertical scaling value)" style to the image element to enlarge the image; 2. Use the overflow attribute to hide the overflowing part of the image element after enlarging it. The syntax is "the parent element of the picture element {overflow:hidden;}".

How to set css to hide overflow after image is enlarged

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

How to hide the overflow after the image is enlarged in css

In css, you can use the transform attribute to enlarge the image. When this attribute is combined with the scale function When used, the element can be scaled. The syntax is as follows:

图片元素{transform:scale(横向缩放值,竖向缩放值);}
Copy after login

Then use the overflow attribute to hide the excess part. This attribute is used to set the style of the element beyond the element. When the attribute value is hidden, it will be hidden. elements beyond.

The syntax is as follows:

元素{overflow:hidden;}
Copy after login

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>
    div{
      width:500px;
      height:300px;
      border:1px solid #000;
      overflow:hidden;
    }
    img{
      transform:scale(1.5,1.5);
    }
  </style>
</head>
<body>
  <div><img src="1118.02.png" alt=""></div>
</body>
</html>
Copy after login

Output result:

How to set css to hide overflow after image is enlarged

(Learning video Share: css video tutorial)

The above is the detailed content of How to set css to hide overflow after image is enlarged. 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