我想将我的网页转换为四个部分,一个水平和三个垂直。横截面没问题,但是竖截面有两个问题:
- 它们没有填满整个屏幕高度。
- 第三部分与第二部分重叠近 10 或 20 个像素。
这是我的 CSS:
body{
width: available;
height: available;
}
.container{
width: available;
height: available;
}
.leftpane{
width: 25%;
min-width: 350px;
height: available;
min-height: 400px;
float: left;
background-color: rosybrown;
border-collapse: collapse;
}
.middlepane{
width: 50%;
min-width: 800px;
height: available;
min-height: 650px;
float: left;
background-color: royalblue;
border-collapse: collapse;
}
.rightpane{
width: available;
height: available;
position: relative;
margin-left: 75%;
background-color: yellow;
border-collapse: collapse;
}
.toppane{
width: available;
height: 100px;
border-collapse: collapse;
background-color: #4da6ff;
}
这是 HTML 页面:
<div class="container">
<div class="toppane">Test Page</div>
<div class="leftpane"><h1>Test Page</h1></div>
<div class="middlepane">Test Page</div>
<div class="rightpane"><h1>Test Page</h1></div>
</div>
我的输出是这样的:
我希望它是这样的:
这是 一个 jsfiddle 。
原文由 Gaurav Mahindra 发布,翻译遵循 CC BY-SA 4.0 许可协议
首先,
width: available
不是有效的属性。如果你想使用所有可用空间,你应该设置width: 100%
。无论如何,为了解决您的问题,您应该使用height: 100%
也用于body
和html
。看这个例子:笔记:
1. 我删除了所有
min-width
和min-height
在这种情况下你不需要这些。2. 将
height: 100%
用于您的元素,您还应该在body
和html
标签上进行设置。3. left pane should be
float: left
withwidth: 25%
, right panefloat: right
width: 25%
and middle panefloat: left
orfloat: right
与width: 50%
就这样!
2022 年更新!
这是通过 flex 更新的版本: