gpt4 book ai didi

html - 可滚动侧边栏内的 Flexbox 粘性页脚

转载 作者:太空宇宙 更新时间:2023-11-03 20:04:58 25 4
gpt4 key购买 nike

我有一个带有页脚的移动侧边栏,该页脚应该固定在底部,但是当有很多导航链接时,页脚会被向下推,您必须滚动才能看到它。

这是一个简化的演示,显示侧边栏已经在内容上展开。您可以看到页脚粘在侧边栏的底部,没有被额外的链接向下推,并且在滚动时它仍然与链接重叠。

body {background: #CCC;}

#side-menu {
position: fixed;
top: 0;
left: 0;
bottom: 0;
width: 200px;
background: #FFF;
box-shadow: 0 0 20px #000;

display: flex;
flex-direction: column;
overflow: auto;
height: 100vh;
}

#side-menu-header,
#side-menu-footer {
flex-shrink: 0;
background-color: skyblue;
padding: 0.5rem;
}

#side-menu-nav {
flex-grow: 1;
display: flex;
flex-direction: column;
}

#side-menu-nav a {
padding: 0.5rem;
}
<aside id="side-menu">
<header id="side-menu-header">
Logo
</header>
<nav id="side-menu-nav">
<a href="#">link</a><a href="#">link</a><a href="#">link</a><a href="#">link</a><a href="#">link</a><a href="#">link</a><a href="#">link</a><a href="#">link</a><a href="#">link</a><a href="#">link</a><a href="#">link</a><a href="#">link</a><a href="#">link</a>
</nav>
<footer id="side-menu-footer">
Footer
</footer>
</aside>

<p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p>

我过去曾使用过 flexbox,但我不知道我做错了什么。如何使页脚显示在导航链接下方?

最佳答案

此外,您的#side-menu-nav 需要有flex-shrink: 0;,否则它会收缩以适合 它的 parent 。

堆栈片段

body {background: #CCC;}

#side-menu {
position: fixed;
top: 0;
left: 0;
bottom: 0;
width: 200px;
background: #FFF;
box-shadow: 0 0 20px #000;

display: flex;
flex-direction: column;
overflow: auto;
height: 100vh;
}

#side-menu-header,
#side-menu-footer {
flex-shrink: 0;
background-color: skyblue;
padding: 0.5rem;
}

#side-menu-nav {
flex-shrink: 0;
flex-grow: 1;
display: flex;
flex-direction: column;
}

#side-menu-nav a {
padding: 0.5rem;
}
<aside id="side-menu">
<header id="side-menu-header">
Logo
</header>
<nav id="side-menu-nav">
<a href="#">link</a><a href="#">link</a><a href="#">link</a><a href="#">link</a><a href="#">link</a><a href="#">link</a><a href="#">link</a><a href="#">link</a><a href="#">link</a><a href="#">link</a><a href="#">link</a><a href="#">link</a><a href="#">link</a>
</nav>
<footer id="side-menu-footer">
Footer
</footer>
</aside>

<p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p><p>lots of content here oh yeah so much content!!!</p>

关于html - 可滚动侧边栏内的 Flexbox 粘性页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54658826/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com