How to capture part of an image using css

WBOY
Release: 2021-12-10 18:05:58
Original
7992 people have browsed it

Method: 1. Use the "position:absolute" style to set the picture element to the absolute positioning style; 2. Use the clip attribute to intercept the picture with the absolute positioning style. The syntax is "picture element {clip:rect" (top,right,bottom,left);}".

How to capture part of an image using css

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

How to use css to intercept part of the picture

In css, you can use the clip attribute to intercept part of the picture. This attribute can be used for absolutely positioned images. The element is clipped.

So we need to set the image to absolute positioning style first, and then use the clip attribute to intercept it.

Possible values ​​of the clip attribute are as follows:

How to capture part of an image using css

Examples are 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>
  img{
    position:absolute;
    clip:rect(0px 100px 200px 0px);
  }
  </style>
</head>
<body>
  <img src="1118.02.png" alt="">
</body>
</html>
Copy after login

Output result:

How to capture part of an image using css

(Learning video sharing: css video tutorial)

The above is the detailed content of How to capture part of an image using css. 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