我正在网页上实现一项功能,允许用户使用 Tab 键进行导航。
当我在页面中切换时,最终页面将不得不自动向下滚动以切换到新内容。发生这种情况时,整个页面会向上移动几个像素,导航栏从页面顶部消失就证明了这一点。 (留在 DOM 中,只是在视线之外)。
演示:
代码:
app.component.html:
<div *ngIf="token" class="route-container">
<app-search [token]="token"></app-search>
<router-outlet></router-outlet>
</div>
app.component.scss:
.route-container {
height: 100%;
flex-direction: column;
justify-content: space-between;
}
app-search{
position: relative;
z-index: 1;
}
search.component.html:
<nav class="navHeader">
...
</nav>
search.component.scss:
.navHeader {
height: 48px;
display: flex;
align-items: center;
color: #808080;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.2), 0 2px 1px -1px rgba(0, 0, 0, 0.12), 0 1px 1px 0 rgba(0, 0, 0, 0.14);
}
为什么会发生这种情况,我该如何解决?
其他信息:
- Angular 8 (8.0.2)
- 在 3 种浏览器(Edge、IE11、Chrome)中对此进行了测试。错误出现在所有 3 个中。
编辑
在尝试@Eliseo 的解决方案后,我将问题的标题从'为什么导航移动' 更改为'为什么整个页面会自动推送' 作为我意识到不仅仅是菜单被推高了几个像素。
谢谢
最佳答案
你问的是什么?
.navHeader {
position: fixed; /* Set the navbar to fixed position */
top: 0; /* Position the navbar at the top of the page */
width: 100%; /* Full width */
}
关于html - 当我在页面中切换时,为什么整个页面会自动向上推几个像素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57589049/