简体   繁体   English

Bootstrap隐藏元素需要放置

[英]Bootstrap Hidden Element Requires Place

I'm using Bootstrap and I have included a navbar at the bottom of the page. 我正在使用Bootstrap,并且在页面底部添加了导航栏。 But The notification bar element (look comment - it is the div element with the id warning . 但是notification bar元素(请看注释-它是带有id warningdiv元素。

The notification bar can change It's visibility. notification bar可以更改其可见性。 But when the visibility is 'collapsed' the div is still taking up all space. 但是,当可见性“崩溃”时,div仍会占用所有空间。

My code: 我的代码:

 <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>

How can I change it so that the div is not taking any space away when the visibility is hidden? 我如何更改它,以便在隐藏可见性时div不占用任何空间?

That is correct. 那是对的。 The visibility could be seen as an opacity... so the element is there but with opacity zero, when hidden. visibility可以看作是不透明性...因此元素存在,但隐藏时不透明度为零。

If you don't want it to use the place, rather use display : 如果您不希望它使用该位置,请使用display

<div class="row"  id="warning" style="display: none;">

Instead of visibility you can use hide class and toggle it 除了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>

Change style="visibility: hidden;" 更改style="visibility: hidden;" to style="display: none; : 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> 

Use 采用

display: none

instead of 代替

visibility: hidden

The difference is well explained on w3schools w3schools上的差异得到了很好的解释

that's the whole idea of visibility: hidden;, it keeps the space even it hides the element. 这就是可见性的整体思想:隐藏;即使隐藏元素也可以保留空间。 But in display:none will leave the space . 但在显示中:没有人会离开空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM