gpt4 book ai didi

html - 100% 高度包装器中的可滚动 Div

转载 作者:行者123 更新时间:2023-11-28 12:30:13 24 4
gpt4 key购买 nike

我试图完成此布局,但我在尝试使 div #content 可滚动(垂直)而不移动整个页面时遇到问题。

HTML:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test Layout</title>
</head>
<body>
<div id="wrapper">
<div id="main">
<div id="sidebar">
<div id="buttonsContainer">
</div>
</div>
<div id="content">
Scrollable content here
</div>
</div>
</div>
</body></html>

CSS:

* {
margin: 0px;
padding: 0px;
}

body {
background-color: #333;
}

body, html , #wrapper {
height: 100%;
overflow: hidden;
}

#wrapper {
width: 986px;
margin-right: auto;
margin-left: auto;
background-color: #2A2A2A;
}

#main {
background-color: #FFF;
width: 970px;
margin-right: auto;
margin-left: auto;
border-right-style: solid;
border-right-width: 2px;
border-right-color: #000;
border-left-style: solid;
border-left-width: 2px;
border-left-color: #000;
height: 100%;
position: relative;
}

#sidebar {
height: 100%;
width: 25%;
float: left;
background-color: #111;
position: absolute;
}

#content {
margin-left: 25%;
overflow: auto;
}

#buttonsContainer {
margin-top: 40%;
height: 300px;
width: 100%;
position: relative;
background-color: #F00;
}

您可以看到此布局托管 here有什么建议吗?

最佳答案

这是一种方法。使用绝对定位拉伸(stretch)您的 #content block 以填充 #wrapper 父 block ,同时留出 25% 的左边距。

从包装器 block 中删除 overflow: hidden,您就可以得到想要的效果。

* {
margin: 0px;
padding: 0px;
}
body {
background-color: #333;
}
body,
html,
#wrapper {
height: 100%;
}
#wrapper {
width: 986px;
margin-right: auto;
margin-left: auto;
background-color: #2A2A2A;
}
#main {
background-color: #FF0;
width: 970px;
margin-right: auto;
margin-left: auto;
border-right-style: solid;
border-right-width: 2px;
border-right-color: #000;
border-left-style: solid;
border-left-width: 2px;
border-left-color: #000;
height: 100%;
position: relative;
}
#sidebar {
height: 100%;
width: 25%;
float: left;
background-color: #111;
}
#content {
position: absolute;
top:0;
right: 0;
left: 25%;
bottom: 0;
background-color: lightgray;
overflow: auto;
}
#buttonsContainer {
margin-top: 10%; /* small value for demo only */
height: 100px;
width: 100%;
position: relative;
background-color: #F00;
}
<div id="wrapper">
<div id="main">
<div id="sidebar">
<div id="buttonsContainer">
</div>
</div>
<div id="content">
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>
Scrollable content here<br>end
</div>
</div>
</div>

关于html - 100% 高度包装器中的可滚动 Div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28788099/

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