Home > Daily Programming > CSS Knowledge > How to achieve the slow enlargement effect of images when hovering the mouse in css3? (image, text + video)

How to achieve the slow enlargement effect of images when hovering the mouse in css3? (image, text + video)

藏色散人
Release: 2018-10-12 13:44:34
Original
14012 people have browsed it

This article mainly introduces you to the specific method to achieve the magnification effect when the mouse slides over the picture.

When we browse major e-commerce websites, the most common dynamic effect of pictures should be the enlargement effect when the mouse moves into the picture or hovers over the picture. The main purpose of achieving such dynamic effects is to highlight product content and improve user experience.

For code novices, this effect is certainly very attractive, but if you want to achieve it through html/css code, you may not know where to start.

In fact, the code implementation is very simple. Below we will use a simple example to introduce to you the method of enlarging the image after the mouse passes.

The html/css code example for the magnification effect of moving the mouse into the picture is as follows:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>html/Css3实现图片缩放</title>
    <style type="text/css">
        #div1{
            width: 500px;
            margin: 150px auto;
        }
        #div1 img{
            transition: all 0.5s;
            border-radius:5px;
            border: #eee solid 2px;
        }
        #div1 img:hover{
            transform: scale(1.5);
        }
    </style>
</head>
<body style="background: #000">
<div id="div1">
    <img  src="123123.png" / alt="How to achieve the slow enlargement effect of images when hovering the mouse in css3? (image, text + video)" >
</div>
</body>
</html>
Copy after login

First visit the front desk, and the picture effect is as shown below:

How to achieve the slow enlargement effect of images when hovering the mouse in css3? (image, text + video)

Then when we hover the mouse over the picture, the effect is as follows:

How to achieve the slow enlargement effect of images when hovering the mouse in css3? (image, text + video)

It is obvious from the picture that the picture has been enlarged.


You can copy this code directly and test it locally. Some of the main css/css3 properties used here are:

border-radius: to div Add a rounded border to the element.

:hover The selector is used to select the element on which the mouse pointer is floating.

transform : Applies a 2D or 3D transform to an element. This property allows us to rotate, scale, move or tilt the element. where, the value scale(x,y) Define the 2D scaling transformation. (This example sets the image zoom to 1.5 times)

transition: An abbreviated attribute used to set four transition attributes. (This example sets the transition time when the image is enlarged to 0.5 seconds to avoid the effect being too abrupt)

This article is about using html/css/css3 to achieve the effect of enlarging the image when the mouse passes over it. Very simple and easy to understand, I hope it will be helpful to friends in need!

If you want to learn more about HTML/css, you can follow the PHP Chinese website

HTML video tutorial and CSS video tutorial, CSS3 video tutorial , welcome everyone to refer to and study!

The above is the detailed content of How to achieve the slow enlargement effect of images when hovering the mouse in css3? (image, text + video). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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