CSS隐藏元素的方式
方式一: visibility 属性visibility 属性默认值是 show ,如果设置为 hidden ,元素会隐藏。元素看不见了,还占有原来的位置(元素的大小依然保持)。方式二: display 属性设置 display:none ,就可以让元素隐藏。彻底地隐藏,不但看不见,也不占用任何位置,没有大小宽高。
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>.隐藏元素的方式</title>
<style>
.box{
width: 400px;
height: 400px;
}
.box1{
background-color: yellow;
/* 隐藏元素1方法1 */
display: none;
}
.box2{
background-color: aqua;
}
</style>
</head>
<body>
<div class="box box1">1</div>
<div class="box box2">2</div>
</body>
</html>
没有隐藏前
方法1display:none
方法2 visibility:hidden