gpt4 book ai didi

html - css 表格上的 100% 高度

转载 作者:太空宇宙 更新时间:2023-11-04 15:31:10 24 4
gpt4 key购买 nike

我正在尝试制作没有固定高度或宽度元素的流畅布局。我的页面主体分为三列(因为我希望它们的高度都相等,所以我决定使用 css 表格)。但是,当我尝试将 100% 高度属性添加到表 div(或表单元格 div)时,它们不会扩展到 div.middle 的完整大小。我用完整的代码为这个问题制作了一个 JS fiddle http://jsfiddle.net/3NMw5/ ,但这里有一个片段:

<body>
<div class='titleBar'>
<div class='wrap'>
<img src='../images/logo.png' />
</div>
</div>
<div class='middle'>
<div class='wrap mainContent'>
<div class='leftColumn'>left here</div>
<div class='center'>center</div>
<div class='rightColumn'>right</div>
</div>
</div>
<div class='footerBar'><div class='wrap'>footer</div></div>
</body>

和CSS:

div.mainContent { display: table; height: 100%;}
div.leftColumn { width: 20%; display: table-cell; background-color: #D2B48C; margin: 0; padding: 0;}
div.rightColumn {width: 20%; display: table-cell;}
div.center {width: 60%; display: table-cell;}

最佳答案

尝试将 height: 200px; 添加到 mainContent。

div.mainContent {
display: table;
height: 200px;
}

Here is the jsFiddle获取代码。

添加 height: 100%; 也应该有效。

您的问题不是列没有拉伸(stretch)到全高,而是 mainContent 没有完全拉伸(stretch)。

--

编辑:好的,所以当您尝试让您的容器变得流畅时,真正的问题就来了,因为对于浏览器来说高度比宽度更难计算。

The problem occurs when you set a percentage height on an element who's parent elements don't have heights set. In other words, the parent elements have a default height: auto;. You are, in effect, asking the browser to calculate a height from an undefined value. Since that would equal a null-value, the result is that the browser does nothing.

为了将div的高度定义为相对高度,您还必须设置父元素的高度。

通过将 height: 100% 添加到 .middle,您会得到接近您所追求的结果。 See the jsFiddle here .

阅读有关高度问题的更多信息 here .

关于html - css 表格上的 100% 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13908868/

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