gpt4 book ai didi

html - 如何将列内容包装到滚动底部?

转载 作者:可可西里 更新时间:2023-11-01 12:58:41 25 4
gpt4 key购买 nike

如何在向下滚动时用浅绿色#left“滚动内容”容器包裹到页面底部?当左栏中没有“滚动内容”时,它也应该拉伸(stretch) 100% 的页面。我认为 fixed container 下的 right column 也应该遵循相同的规则。

.wrapper,
html,
body {
height: 100%;
margin: 0;
}

.wrapper {
display: flex;
/* flex-flow: column wrap; */
flex-direction: column;
/* align-items: stretch; */
height: 100%;
}

.top {
height: 60px;
}

.content {
flex-direction: row;
align-items: stretch;
display: flex;
flex: 1;
height: 100%;
}

nav {
height: 60px;
background: tomato;
position: fixed;
top: 0;
width: 100%;
}

#left {
display: flex;
background: lightgreen;
flex: 0 0 40%;

/* justify-content: center; */
flex-direction: column;
/* flex-wrap: wrap; */
}
#left > p {
flex: 1;
}

#right {
display: flex;
flex: 0 0 60%;
}

#fixed {
position: fixed;
background: aqua;
width: 60%;
/* height: 100%; */
}
<div class="wrapper">
<div class="top">
<nav role='navigation'>
</nav>
</div>

<div class="content">
<div id="left">
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
</div>
<div id="right">
<div id="fixed">
<p>This content should not scroll</p>
<p>This content should not scroll</p>
<p>This content should not scroll</p>
<p>This content should not scroll</p>
<p>This content should not scroll</p>
<p>This content should not scroll</p>
<p>This content should not scroll</p>
</div>
</div>
</div>
</div>

最佳答案

/* .wrapper,  */   /* removed this */
html,
body {
height: 100%;
margin: 0;
}

.wrapper {
display: flex;
/* flex-flow: column wrap; */
flex-direction: column;
/* align-items: stretch; */
min-height: 100%; /* changed here */
}

.top {
height: 60px;
}

.content {
flex-direction: row;
align-items: stretch;
display: flex;
flex: 1;
height: 100%;
}

nav {
height: 60px;
background: tomato;
position: fixed;
top: 0;
width: 100%;
}

#left {
display: flex;
background: lightgreen;
flex: 0 0 40%;

/* justify-content: center; */
flex-direction: column;
/* flex-wrap: wrap; */
}
#left > p {
flex: 1;
}

#right {
display: flex;
flex: 0 0 60%;
}

#fixed {
position: fixed;
background: aqua;
width: 60%;
/* height: 100%; */
}
<div class="wrapper">
<div class="top">
<nav role='navigation'>
</nav>
</div>

<div class="content">
<div id="left">
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
<p>Scrolling Content</p>
</div>
<div id="right">
<div id="fixed">
<p>This content should not scroll</p>
<p>This content should not scroll</p>
<p>This content should not scroll</p>
<p>This content should not scroll</p>
<p>This content should not scroll</p>
<p>This content should not scroll</p>
<p>This content should not scroll</p>
</div>
</div>
</div>
</div>

关于html - 如何将列内容包装到滚动底部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45055304/

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