首页 > 其他 > 详细

display:none和visibility:hidden

时间:2019-12-12 10:14:42      阅读:89      评论:0      收藏:0      [点我收藏+]

w3school学习网:https://www.w3school.com.cn/tiy/t.asp?f=hdom_style_display_none

display: none----将元素的显示设为无,即在网页中不占任何的位置。

visibility: hidden----将元素隐藏,但是在网页中该占的位置还是占着。

两者区别:

display:none ---不为被隐藏的对象保留其物理空间,即该对象在页面上彻底消失。

技术分享图片
<html>
<head>
<script type="text/javascript">
function removeElement()
{
document.getElementById("p1").style.display="none";
}
</script>
</head>
<body>

<h1>This is a header</h1>

<p id="p1">This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>

<input type="button" onclick="removeElement()" value="Do not display paragraph" />

</body>
</html>
display="none"

技术分享图片

 

 点击按钮:

技术分享图片

 

 

visibility:hidden--- 使对象在网页上不可见,但该对象在网页上所占的空间没有改变。例如有三个table,将中间的一个table hidden掉,你会发现在那个被hidden的table看不见了,但是,中间会留有很大的一空白,而这个空白就是这个table没有被隐藏时所占的位置。

技术分享图片
<html>
<head>
<script type="text/javascript">
function removeElement()
{
document.getElementById("p1").style.visibility="hidden";
}
</script>
</head>
<body>

<h1>This is a header</h1>

<p id="p1">This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p>

<input type="button" onclick="removeElement()" value="Do not display paragraph" />

</body>
</html>
visibility:hidden

运行截图:

技术分享图片

display:none和visibility:hidden

原文:https://www.cnblogs.com/sengzhao666/p/12027320.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!