Bootstrap 4 multiple fixed Navbars with animated shrink

前端 未结 1 1777
死守一世寂寞
死守一世寂寞 2021-01-03 06:09

I have two Navbars with fixed-top classes displayed one below the other - second one having top: *height of first navbar* css added to it.

相关标签:
1条回答
  • 2021-01-03 06:43

    I think you should wrap both navbars in a single DIV, and make that the data-toggle="affix" element. This way you only make the outer DIV fixed, and the second navbar will naturally follow the height of the 2nd since both are static position.

    https://www.codeply.com/go/DpHESPqZsx

    <div class="fixed-top" data-toggle="affix">
        <div class="navbar navbar-dark bg-dark navbar-expand-sm py-5" id="first">
            ... 
        </div>
        <div class="navbar navbar-light bg-light navbar-expand-sm" id="second">
            ...
        </div>
    </div>
    

    Adjust the CSS to apply the padding animation to the top navbar instead of the affix element:

    .fixed-top #first { 
      -webkit-transition:padding 0.2s ease;
      -moz-transition:padding 0.2s ease; 
      -o-transition:padding 0.2s ease;        
      transition:padding 0.2s ease;  
    }
    
    .affix #first {
      padding-top: 0.2em !important;
      padding-bottom: 0.2em !important;
      -webkit-transition:padding 0.2s linear;
      -moz-transition:padding 0.2s linear;  
      -o-transition:padding 0.2s linear;         
      transition:padding 0.2s linear;  
    }
    
    0 讨论(0)
提交回复
热议问题