hover伪类
- 用法一:悬于自身
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
<style>
#box1 {width: 200px; height: 200px; background: red}
#box2 {width: 100px; height: 100px; background: blue;}
#box1:hover {background: #CB5EC6}
</style>
</head>
<body>
<div id="box1">
<!-- <a href="#">连接</a>-->
<!-- <div id="box2"></div>-->
</div>
</body>
</html>
- 用法二:悬于父类作用于子类
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
<style>
#box1 {width: 200px; height: 200px; background: red}
#box2 {width: 100px; height: 100px; background: blue;}
#box1:hover #box2 {background: #CB5EC6}
</style>
</head>
<body>
<div id="box1">
<!-- <a href="#">连接</a>-->
<div id="box2"></div>
</div>
</body>
</html>
注意事项:
- 只可悬浮于父类作用于子类,不可悬浮于子类作用于父类;
- 悬浮于同一级,不能作用于同一级;
总结:只可以悬于自身或者悬于父类作用于子类,其他的都不行!!!