[英]Bootstrap Hidden Element Requires Place
我正在使用Bootstrap,并且在页面底部添加了导航栏。 但是notification bar
元素(请看注释-它是带有id warning
的div
元素。
notification bar
可以更改其可见性。 但是,当可见性“崩溃”时,div仍会占用所有空间。
我的代码:
<div class="navbar navbar-default navbar-fixed-bottom">
<!-- notification bar element can change visibility -->
<div class="row" id="warning" style="visibility: hidden;">
<h2>Bottom Notification</h2>
<small>Timestamp</small>
<h3>This is a message.</h3>
</div>
<!-- -->
<!-- element is static - can't change visibility -->
<div class="container row">
<p class="navbar-text pull-left">© 2016 - xxxx</p>
</div>
</div>
我如何更改它,以便在隐藏可见性时div不占用任何空间?
那是对的。 visibility
可以看作是不透明性...因此元素存在,但隐藏时不透明度为零。
如果您不希望它使用该位置,请使用display
:
<div class="row" id="warning" style="display: none;">
除了visibility
您还可以使用hide
类并对其进行切换
<div class="navbar navbar-default navbar-fixed-bottom">
<!-- notification bar element can change visibility -->
<div class="row hide" id="warning">
<h2>Bottom Notification</h2>
<small>Timestamp</small>
<h3>This is a message.</h3>
</div>
<!-- -->
<!-- element is static - can't change visibility -->
<div class="container row">
<p class="navbar-text pull-left">© 2016 - xxxx</p>
</div>
</div>
更改style="visibility: hidden;"
为style="display: none;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <div class="navbar navbar-default navbar-fixed-bottom"> <!-- notification bar element can change visibility --> <div class="row" id="warning" style="display: none;"> <h2>Bottom Notification</h2> <small>Timestamp</small> <h3>This is a message.</h3> </div> <!-- --> <!-- element is static - can't change visibility --> <div class="container row"> <p class="navbar-text pull-left">© 2016 - xxxx </p> </div> </div>
这就是可见性的整体思想:隐藏;即使隐藏元素也可以保留空间。 但在显示中:没有人会离开空间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.