GPT4 都无法修复的“CSS+DIV 自动填充高度并显示自动滚动条”

1 天前
 atfeel
以下 HTML 代码,我搞不定,丢给 GPT4 也搞不定,由于 title 和 sendbox 高度固定的,如何让 chat-container 自动填充 right 的剩余高度,再让 chat-container 的内容会超出当前高度时自动显示滚动条,我已经尽力了,chat-container 依然还是被撑破高度,向各位大佬请教了


<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<style>
html, body{height:100%;margin:0; overflow:hidden;}
body{display: flex;justify-content: center; align-items: center;}

.main{display:flex;flex-direction:column;width:100%;height:100%;background-color:#F9F9F9;border:#cccccc 1px solid;box-sizing:content-box;}
.main .top{height:50px;box-sizing:border-box;display:flex;background-color:#D8D8D8;border-radius:0px;margin-bottom:2px;}

.main .bottom{flex: 1;display:flex;}
.main .bottom .left{width:215px;height:100%;padding:3px;box-sizing:border-box;border-right:#E3E3E3 5px solid;overflow-y:auto;}
.main .bottom .right {flex:1;height:100%;display:flex;overflow:hidden;flex-direction:column;border-top-right-radius:10px;border-bottom-right-radius:10px;}
.main .bottom .right .title {height:40px;line-height:40px;padding:0 10px;background-color:#F0F0F0;border:#e3e3e3 1px solid;margin:10px;display:flex;flex-direction:row;}
.main .bottom .right .chat-container{display:flex;flex:1;flex-direction:column;gap:13px;margin:0 10px;padding:20px;overflow-y:auto;position:relative;}
.main .bottom .right .sendbox{height:180px;margin-top:10px;border-top:#e3e3e3 1px solid;box-sizing:border-box;display:flex;flex-direction:column;box-sizing:border-box;}

</style>
</head>
<body>
<div class="main">
<div class="top">
ggggggggg
</div>
<div class="bottom">
<div class="left">
<ul class="clientlist no-select">
<center>测试...</center>
</ul>
</div>
<div class="right">
<div class="title">
111111
</div>
<div class="chat-container">
<div style="height:700px;border:1px solid #ccc;">这里是内容框</div>
</div>
<div class="sendbox">
33333333
</div>
</div>
</div>
</div>
</body>
</html>
849 次点击
所在节点    程序员
5 条回复
yxcoder
1 天前
上面定高 h1 ,下面定高 h2

中间高度是 calc(100% - [h1+h2]px)
不要用 flex
zhyl
1 天前
.main .bottom 加上 overflow: hidden;
oouz
1 天前
这样?

<!DOCTYPE html>
<html lang="zh-CN">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<style>
html,
body {
height: 100%;
margin: 0;
}

body {
display: flex;
justify-content: center;
align-items: center;
}

.main {
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
background-color: #F9F9F9;
box-sizing: content-box;
}

.main .top {
height: 50px;
box-sizing: border-box;
display: flex;
background-color: #D8D8D8;
border-radius: 0px;
margin-bottom: 2px;
}

.main .bottom {
flex: 1;
display: flex;
height: 0;
}

.main .bottom .left {
width: 215px;
height: 100%;
padding: 3px;
box-sizing: border-box;
border-right: #E3E3E3 5px solid;
overflow-y: auto;
}

.main .bottom .right {
flex: 1;
height: 100%;
display: flex;
flex-direction: column;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
}

.main .bottom .right .title {
height: 40px;
line-height: 40px;
padding: 0 10px;
background-color: #F0F0F0;
border: #e3e3e3 1px solid;
margin: 10px;
display: flex;
flex-direction: row;
}

.main .bottom .right .chat-container {
flex: 1;
height: 0;
gap: 13px;
margin: 0 10px;
padding: 20px;
overflow-y: auto;
border: 1px solid #eee;
}

.main .bottom .right .sendbox {
height: 180px;
margin-top: 10px;
border-top: #e3e3e3 1px solid;
box-sizing: border-box;
display: flex;
flex-direction: column;
box-sizing: border-box;
}
</style>
</head>

<body>
<div class="main">
<div class="top">
ggggggggg
</div>
<div class="bottom">
<div class="left">
<ul class="clientlist no-select">
<center>测试...</center>
</ul>
</div>
<div class="right">
<div class="title">
111111
</div>
<div class="chat-container">
<div style="height:700px;border:1px solid #fff;background-color: #fff;">这里是内容框</div>
</div>
<div class="sendbox">
33333333
</div>
</div>
</div>
</div>
</body>

</html>
shintendo
1 天前
听我的,chat-container 的 flex: 1 改成 flex: 1 1 0 ,并去掉 display: flex
atfeel
1 天前
经测试,在 bottom 加上 display: flex;height: 100%;,就能正常了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1100157

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX