定义两个盒子,class =“in”,class=“out”,当我鼠标移入in 时操作显示out
.in:hover + .out{ //这个是必须要相邻的兄弟元素
display: block;
}
还有一个
.in:hover ~.out{ //这个是选中in下面的兄弟元素,可以不相邻,但只选择第一个类名字为out的
display: block;
}
一个小案例(可以看下效果)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.max{
width: 300px;
height: 260px;
background-color: pink;
position: relative;
}
.in{
width: 200px;
height: 200px;
border-radius: 50%;
background-color: rebeccapurple;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: auto;
}
.out{
width: 290px;
height: 250px;
background-color: red;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: auto;
display: none;
opacity: 0.3;
}
.in:hover + .out{
display: block;
}
</style>
</head>
<body>
<div class="max">
<div class="in"></div>
<div class="out"></div>
</div>
</body>
</html>