Html 隐藏的div占用空间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16250700/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hidden divs taking up space
提问by Shaun Wilson
I've set up all my navigation for my website as hide.show divs (using behaviours). It all works pretty well, but I've now realised the problem of the divs taking up space even when they're hidden, extending the height of my wrapper far too much.
我已将我的网站的所有导航设置为 hide.show divs(使用行为)。这一切都运行良好,但我现在意识到即使隐藏 div 也会占用空间的问题,将我的包装器的高度扩展得太多。
I really want the height to extend and contract according to the amount of content on display.
我真的希望高度根据显示的内容量来扩展和收缩。
http://shanuea.lockernerd.co.uk/camel/
http://shanuea.lockernerd.co.uk/camel/
The divs are absolutely positioned and set to visibility:hidden. Any help appreciated, please let me know if you need more info.
div 绝对定位并设置为可见性:隐藏。感谢任何帮助,如果您需要更多信息,请告诉我。
回答by Stefan Haustein
Use display:none instead of visibility:hidden if you want the divs to take up no space when they are not displayed.
如果您希望 div 在未显示时不占用空间,请使用 display:none 而不是可见性:隐藏。
回答by Webdevotion
Just a reminder to future googlers:
I had some <span>
tags which I wanted to hide from visitors. Behind each <span>
was a <br>
. The <br>
tags made it look like the <span>
tags were still taking up space after setting their display
property to none
.
提醒未来的谷歌员工:
我有一些<span>
标签,我想对访问者隐藏。每<span>
一个后面都有一个<br>
。该<br>
标签使得它看起来像<span>
标签被他们的设置后,仍然占用空间display
属性none
。