区分网格style.visibility和style.display [英] Difference betweet style.visibility and style.display

查看:200
本文介绍了区分网格style.visibility和style.display的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

visibility:hidden和display:none之间有什么区别


我在使用JavaScript隐藏/显示 div 标签的示例。
在某些示例中,他们使用 visibility 和一些显示



例如

  document.getElementById(divhotel)。style.visibility =hidden; 

vs

  document.getElementById(divhotel)。style.display =none; 

两者之间有什么区别?

解决方案

设置 visibility hidden ,元素不会显示,但仍占用页面上相同的空间。 p>

当您获得 显示 none ,元素既不显示也不占用页面上的任何空间。 / p>

我经常发现自己使用 display ,但这取决于您的场景需求。


Possible Duplicate:
What is the difference between visibility:hidden and display:none

I am looking at examples to hide/show div tags using JavaScript. In some examples, they use visibility and in some display.

e.g.

document.getElementById("divhotel").style.visibility = "hidden";

vs

document.getElementById("divhotel").style.display = "none";

What is the difference between the two?

解决方案

When you set visibility to hidden, the element is not shown but still takes up the same space on the page.

When you get display to none, the element is neither shown nor does it take up any space on the page.

More often than not I find myself using display, but it depends on what your scenario demands.

这篇关于区分网格style.visibility和style.display的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆