我的项目有以下结构:
<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>
粘性导航栏不起作用,因为它只能在其组件内部工作,我怎样才能使其适用于组件并保持在顶部。
我尝试将其放入 app.component.html 但它不起作用。
HTML 在容器内排列应用程序组件,包括顶部的应用程序导航栏,后面是其他组件。填充为粘性导航栏提供了空间。 CSS 将 app-nav-bar 样式设置为以背景颜色、白色文本和填充固定在顶部。由于位置:粘性,它在滚动期间保持固定;。
/* Apply basic styling to ensure the navigation bar takes up space */
.app-container {
position: relative;
padding-top: 60px; /* Adjust this value to match the height of your navigation bar */
}
/* Style for the sticky navigation bar */
app-nav-bar {
position: sticky;
top: 0;
background-color: #333;
color: white;
padding: 10px 0;
text-align: center;
z-index: 100; /* Ensure the navigation bar is above other content */
}
/* Rest of your component styles */
<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>