search

Home  >  Q&A  >  body text

Way to make sticky navigation bar work inside other components?

<p>I have the following structure in my project: </p> <pre class="brush:php;toolbar:false;"><app-nav-bar></app-nav-bar> <app-slider></app-slider> <app-solution></app-solution> <app-platform></app-platform> <app-team></app-team> <app-contact></app-contact> <app-footer></app-footer></pre> <p>The sticky navigation bar is not working as it only works within its component, how to make it work within the component and keep it on top. </p> <p>I tried putting it in app.component.html but it doesn't work. </p>
P粉579008412P粉579008412468 days ago467

reply all(1)I'll reply

  • P粉755863750

    P粉7558637502023-08-16 00:52:35

    HTML arranges application components in a container, including app-nav-bar on top, followed by other components. Padding provides space for a sticky navigation bar. CSS styles app-nav-bar to make it sticky on top, with background color, white text and padding. It stays fixed while scrolling due to position: sticky;.

    /* 应用基本样式以确保导航栏占用空间 */
    .app-container {
      position: relative;
      padding-top: 60px; /* 根据导航栏的高度调整此值 */
    }
    
    /* 粘性导航栏的样式 */
    app-nav-bar {
      position: sticky;
      top: 0;
      background-color: #333;
      color: white;
      padding: 10px 0;
      text-align: center;
      z-index: 100; /* 确保导航栏在其他内容之上 */
    }
    
    /* 其余组件的样式 */
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
    <div class="app-container">
      <app-nav-bar></app-nav-bar>
      <app-slider></app-slider>
      <app-solution></app-solution>
      <app-platform></app-platform>
      <app-team></app-team>
      <app-contact></app-contact>
      <app-footer></app-footer>
    </div>

    reply
    0
  • Cancelreply