相同点:
display:none;和visibility:hidden;都是使元素隐藏
设置前:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div style="width: 100px;height: 100px;background: red;"></div>
<p>没有设置display:none;</p>
<div style="width: 100px;height: 100px;background: pink;"></div>
<p>没有设置visibility:hidden;</p>
</body>
</html>
效果图:
设置后:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div style="width: 100px;height: 100px;background: red;display:none;"></div>
<p>设置display:none;元素被隐藏</p>
<div style="width: 100px;height: 100px;background: pink;visibility:hidden;"></div>
<p>设置visibility:hidden;元素被隐藏</p>
</body>
</html>
效果图:
**
**
不同点:
**
display:none;将元素的显示设为无,即在网页中不占任何的位置;
visibility: hidden----将元素隐藏,但是在网页中该占的位置还是占着
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div style="width: 100px;height: 100px;background: red;display:none;"></div>
<p>设置display:none;元素被隐藏</p>
<div style="width: 100px;height: 100px;background: pink;visibility:hidden;"></div>
<p>设置visibility:hidden;元素被隐藏</p>
</body>
</html>
效果图: