How to set the mouse to display the image when passing through the element in css

青灯夜游
Release: 2023-01-07 11:44:44
Original
10905 people have browsed it

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);}".

How to set the mouse to display the image when passing through the element in css

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>
Copy after login

Effect picture:

How to set the mouse to display the image when passing through the element in css

(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!

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