可见性:隐藏和显示:无之间有什么区别? [英] What is the difference between visibility:hidden and display:none?
问题描述
CSS 规则 visibility:hidden
和 display:none
都导致元素不可见.这些是同义词吗?
The CSS rules visibility:hidden
and display:none
both result in the element not being visible. Are these synonyms?
推荐答案
display:none
意味着有问题的标签根本不会出现在页面上(尽管你仍然可以通过dom).其他标签之间不会为它分配空间.
display:none
means that the tag in question will not appear on the page at all (although you can still interact with it through the dom). There will be no space allocated for it between the other tags.
visibility:hidden
表示与 display:none
不同,标签不可见,但在页面上为其分配了空间.标记已呈现,只是在页面上看不到.
visibility:hidden
means that unlike display:none
, the tag is not visible, but space is allocated for it on the page. The tag is rendered, it just isn't seen on the page.
例如:
test | <span style="[style-tag-value]">Appropriate style in this tag</span> | test
用 display:none
替换 [style-tag-value]
结果:
test | | test
用 visibility:hidden
替换 [style-tag-value]
结果:
test | | test
这篇关于可见性:隐藏和显示:无之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!