opacity的意思是不透明性,opacity取值范围为0-1;opacity:0;表示完全透明,opacity:1;表示完全不透明。
opacity:0 于overflow:hidden不同,overflow:hidden会完全消除空间,opacity:0 只是视觉上看不到,但是实际上会占用空间,这点我们常用来于:hover一起使用。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>demo</title>
<style>
.love{
background: url(1.jpg) no-repeat;
border: 300px;
height: 300px;
color: red;
opacity: 1;
position: relative;
}
.yes{
opacity: 0;
position: relative;
top: 100px;
left: 110px;
width: 200px;
height: 100px;
}
.love:hover .yes{
opacity: 1;
transition: 2s;
}
</style>
</head>
<body>
<div class="love">
<div class="yes">佐助和鸣人才是真爱!!</div>
</div>
</body>
</html>