Home >Web Front-end >CSS Tutorial >How to set the mouse to display the image when passing through the element in css
In css, you can use the ":hover" selector to achieve the effect of displaying pictures when the mouse passes over an element. The ":hover" selector is used to specify the special style added when the mouse pointer floats on an element. The syntax format "element" :hover{background: url(picture address);}".
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
In CSS, you can use the ":hover" selector to achieve the effect of displaying pictures when the mouse passes over the element.
: The hover selector specifies a special style that is added when the mouse moves over the element.
Let’s take a closer look through the code example:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style type="text/css"> div{ width: 400px; height: 300px; border: 1px solid red; } div:hover{ background: url(img/1.jpg); background-size: 400px; } </style> </head> <body> <div>将鼠标移动到div盒子中:</div> </body> </html>
Effect picture:
(Learning video sharing: css video tutorial)
The above is the detailed content of How to set the mouse to display the image when passing through the element in css. For more information, please follow other related articles on the PHP Chinese website!