Home  >  Article  >  Web Front-end  >  How to achieve the effect of displaying pictures after mouse click in css

How to achieve the effect of displaying pictures after mouse click in css

WBOY
WBOYOriginal
2021-11-30 15:44:569512browse

In CSS, you can use the ":active" selector and the "background-image" attribute to achieve the effect of displaying an image on a mouse click. The syntax is "element: active{background-image:url(picture path); }".

How to achieve the effect of displaying pictures after mouse click in css

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

#How to display the picture effect after mouse click in css

You can use: active selector and background-image attribute to realize the display after mouse click Image effects, :active selector is used to select active links. When you click on a link, it becomes active (activated). The background-image attribute is used to set the image displayed after clicking.

The example is as follows:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <style type="text/css">
            div{
                width: 400px;
                height: 300px;
                border: 1px solid red;  
            }
            div:active{
                background-image: url(1118.02.png);
                background-size: 400px;
            }
        </style>
    </head>
    <body>
        <div>鼠标点击div盒子</div>
    </body>
</html>

Output result:

How to achieve the effect of displaying pictures after mouse click in css

(Learning video sharing: css video tutorial)

The above is the detailed content of How to achieve the effect of displaying pictures after mouse click in css. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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