Use CSS to achieve 3D convex and concave effects on images (convex out of the frame or concave in the frame)

Use CSS to achieve 3D convex and concave effects on images (convex out of the frame or concave in the frame)

Ⅰ. Problem description:

Use CSS to achieve 3D convex and concave effect of pictures;

ⅡThe implementation process is as follows:

1. The display results are:
A. Normal pictures (both Picture 1 and Picture 2 are normal):

insert image description here

B. The image 1 is protruding out of the frame, while the image 2 is normal;
Trigger process: Place the mouse within the red frame of Figure 1, and the result will be displayed;

insert image description here

C. Picture 1 is normal, Picture 2 is sunken into the frame;
Trigger process: put the mouse in the red frame of Figure 2, and the result will be displayed;

insert image description here

2. Run the software VScode , and it can be realized by personal test;

3. Run the code:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        .wrap {
            float: left;
            width: 200px;
            height: 300px;
            border: 1px solid red;
            margin: 100px 0 0 100px;
            perspective:500px;
            /* 
            "perspective:500px;" means: perspective distance (effect of small things in the distance and large things near);
            But only the feeling has changed, and the actual size has not changed;
             */
        }

        .wrap img {
            transition: 0.5s;
        }

        .wrap:nth-child(1):hover img {
            transform: translateZ(100px);
            /* "translateZ(100px);" means: translate 100px in the positive direction of the Z axis (vertical to the outside of the screen is positive); */
        }

        .wrap:nth-child(2):hover img {
            transform: translateZ(-100px);
            /* "translateZ(-100px);" means: translate 100px in the negative direction of the Z axis (negative inwards vertically on the screen); */
        }
      
    </style>
</head>
<body>

<div class="wrap">
    <img src="pic02.jpg"/>
</div>
<!-- 
    The src address in img at this time refers to the address of the image you loaded. When the address of the image and the code document are in the same directory, the address can be simply introduced like the above code;
 -->
<div class="wrap">
    <img src="pic02.jpg"/>
</div>

</body>
</html>

III. Conclusion

This is the end of this article about how to use CSS to achieve 3D convex and concave effects on images (protruding outside the frame or sunken into the frame). For more relevant content about how to use CSS to achieve 3D convex and concave effects, please search previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

<<:  How to use React to implement image recognition app

>>:  Detailed explanation of the relationship between Linux and GNU systems

Recommend

Detailed steps to configure MySQL remote connection under Alibaba Cloud

Preface As we all know, by default, the MySQL ins...

Use the njs module to introduce js scripts in nginx configuration

Table of contents Preface 1. Install NJS module M...

Mysql implements three functions for field splicing

When exporting data to operations, it is inevitab...

MySQL implements an example method of logging in without a password

Specific method: Step 1: Stop the mysql service /...

Explanation of nginx load balancing and reverse proxy

Table of contents Load Balancing Load balancing c...

Tomcat multi-instance deployment and configuration principles

1. Turn off the firewall and transfer the softwar...

JavaScript programming through Matlab centroid algorithm positioning learning

Table of contents Matlab Centroid Algorithm As a ...

A brief discussion on the font settings in web pages

Setting the font for the entire site has always b...

Vue3+script setup+ts+Vite+Volar project

Table of contents Create a vue + ts project using...

Native JS to implement breathing carousel

Today I will share with you a breathing carousel ...