根据我在评论中建议的答案,我能够在 chrome 中工作以到达下面的 css。
1) 在 .sidebar-nav 组件中添加一些 css
nav.sidebar-nav {
position: absolute;
overflow-y: scroll;
top: 100px; /*100px to give some room for the sidebar heading (without this, absolute position will make the nav overlap)*/
left: 15px; /* you can make this zero and add `padding-left: 15px` */
bottom: 15px; /* leave some room for copyright section */
right: -17px; /*this may vary from browser to browser (i suggest using the width of the widest scrollbar, then adjust for padding-right)*/
padding-right: 15px; /*padding to prevent the text from flowing off screen*/
}
2) .container 类变为
.sidebar .container{
max-width: 38rem;
padding-left: 1rem;
padding-right: 1rem;
margin-left: auto;
margin-right: auto;
height: 100%;
position: relative;
overflow: hidden;
}
3) 确保在将.sidebar-nav 设为绝对后,页脚位仍位于底部
.sidebar .container > p:last-of-type {
position: absolute;
bottom: -15px;
}
当然,正如原始解决方案中提到的,您必须在不同的浏览器中测试滚动条的宽度,以达到正确的宽度,以代替步骤 1 中的right: -17px。