html - 当我在页面中切换时,为什么整个页面会自动向上推几个像素?

标签 html css angular keyboard accessibility

我正在网页上实现一项功能,允许用户使用 Tab 键进行导航。

当我在页面中切换时,最终页面将不得不自动向下滚动以切换到新内容。发生这种情况时,整个页面会向上移动几个像素,导航栏从页面顶部消失就证明了这一点。 (留在 DOM 中,只是在视线之外)。

演示:

Demo: The navigation bar disappears when tabbing

代码:

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/

相关文章:

Angular 5 + Angular Material Select + Reactive Forms == 没有显示初始选项

Angular2 在订阅上设置变量不起作用

html - IE frameBorder替代方案

html - 在 CSS 流布局中自动调整图像大小以模拟 html-table 布局

.net - 是否有 HTML 5 的 Web 套接字的 WCF 服务器实现?

html - CSS 如何在固定居中 Logo 的任一侧创建响应线

html - 如何将 bootstrap 3 添加到 meteor1.1.0.2 元素

Angular 2 指令及其属性

javascript - 结合 Angular 和 React 来简化

html - 如何在没有绝对定位或将图像设置为背景的情况下将文本放在图像上