gpt4 book ai didi

javascript - css/div - 定位 div 的顶部、左侧、右侧、底部和中心,仅填充 _visible_ 页面

转载 作者:搜寻专家 更新时间:2023-10-31 23:03:57 25 4
gpt4 key购买 nike

大多数人告诉我不要使用表格创建页面布局,而是使用 div 和 CSS。酷-我可以接受。很抱歉提出一个基本问题。

我想让中心(内容)向左、右、顶部和底部延伸到可见页面。如果内容超出具有 T、L、R、B div 的可见页面,它可以滚动。左、右、上、下 div 固定在它们在可见页面中的位置。兜兜转转,我永远也到不了那里。

关于如何攻击这个有什么建议吗?

|--------------------------------|  <--- Visible page
| Top |
|--------------------------------| Right/left fixed with stretched height
|------| Center/content |------| Top/bottom fixed height stretched width
|------| |------|
|------| ^ |------|
|------| | |------|
| Left | <--stretch--> | Right|
|------| | |------|
|------| v |------|
|------| |------|
|--------------------------------|
| Bottom |
|--------------------------------|

下面是基本代码,没有为 div 定位。我玩过各种位置/绝对/相对等,但总是从顶部和底部 div 中得到一些奇怪的溢出。

<body>
<style>
.container {
border: 3px solid #FF00FF;
width: 100%;
height: 100%;
}

.top {
background: red;
height: 3em;
width: 100%;
}

.bottom {
background: blue;
height: 3em;
bottom: 0;
}

.left {
background: green;
width: 5em;
}

.right {
background: gold;
width: 5em;
}

.content {
background: lightgreen;
height: 100%;
width: 100%;
}
</style>

<div class="container">
<div class="top">
Top
</div>

<div class="left">
Left
</div>

<div class="content">
Content
</div>

<div class="right">
Right
</div>
<div class="bottom">
Bottom
</div>
</div>
</body>

最佳答案

html, body {
height:100%;
}
.container {
position:relative;
width: 100%;
height: 100%;
}
.top {
height: 50px;
width: 100%;
background: red;
}
.left {
position:absolute;
top:50px;
left:0;
bottom:50px;
width: 50px;
background: green;
}
.right {
position:absolute;
top:50px;
right:0;
bottom:50px;
width: 50px;
background: gold;
}
.bottom {
position:absolute;
bottom:0;
width: 100%;
height: 50px;
background: blue;
}
.content {
position:absolute;
top:50px;
left:50px;
right:50px;
bottom:50px;
background: lightgreen;
overflow:scroll;
}

像这样的东西 JSFiddle

旁注:除非父元素明确设置了高度,否则以 % 表示的高度将不起作用...

关于javascript - css/div - 定位 div 的顶部、左侧、右侧、底部和中心,仅填充 _visible_ 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23172892/

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