首页 > 解决方案 > 粘性侧边栏在 Firefox 中没有正确的顶部空间

问题描述

我无法使用 Firefox 显示整个侧边栏。正如您从图像中看到的那样,它接缝不能从顶部正确地间隔,隐藏了第一个项目!

图 1

这是CSS:

/*
* Sidebar
*/

.sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100; /* Behind the navbar */
  padding: 0;
  box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
}

.sidebar-sticky {
  position: -webkit-sticky;
  position: sticky;
  top: 48px; /* Height of navbar */
  height: calc(100vh - 48px);
  padding-top: .5rem;
  overflow-x: hidden;
  overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */
}

.sidebar .nav-link {
  font-weight: 500;
  color: #333;
}

.sidebar .nav-link .feather {
  margin-right: 4px;
  color: #999;
}

.sidebar .nav-link.active {
  color: #007bff;
}

.sidebar .nav-link:hover .feather,
.sidebar .nav-link.active .feather {
  color: inherit;
}

.sidebar-heading {
  font-size: .75rem;
  text-transform: uppercase;
}

这是引导模板之一的一部分!

预先感谢您的帮助!

标签: htmlcsstwitter-bootstrapbootstrap-4

解决方案


因为它在网格内并使用响应式类,所以当您使窗口变小或变大时,“间距”会发生变化。

<div class="row">
    <nav class="col-md-2 d-none d-md-block bg-light sidebar">
        <div class="sidebar-sticky">...</div>
    </nav>
    <main role="main" class="col-md-9 ml-sm-auto col-lg-10 px-4">
        ...
    </main>
</div>

推荐阅读