display:none; visiblity:hidden; overflow:hidden;都能用来隐藏与显示元素
<!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>
</head>
<style>
.top {
width: 300px;
height: 300px;
background-color: aqua;
}
.bottom {
width: 300px;
height: 300px;
background-color: pink;
}
</style>
<body>
<div class="top"></div>
<div class="bottom"></div>
</body>
</html>
1.display和visbility的区别?
那我们加入给top盒子加入display:none,会发现隐藏元素而且不占有原来的位置
给top盒子加入visiblity:hidden.会发现隐藏元素占有原来的位置
总结: 都能隐藏元素,前者设置的元素不占有原来的位置,后者隐藏的元素会占有原来的位置
overflow的作用
是用来溢出隐藏,将超出盒子边缘的部分给隐藏起来