如何在不指定父级高度的情况下强制子级div为父级div的高度的100%?

编程入门 行业动态 更新时间:2024-10-28 06:27:11
本文介绍了如何在不指定父级高度的情况下强制子级div为父级div的高度的100%?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个具有以下结构的网站:

I have a site with the following structure:

<div id="header"></div> <div id="main"> <div id="navigation"></div> <div id="content"></div> </div> <div id="footer"></div>

导航在左侧,内容div在右侧.内容div的信息是通过PHP提取的,因此每次都不同.

The navigation is on the left and the content div is on the right. The information for the content div is pulled in through PHP, so it's different every time.

无论加载哪个页面,如何垂直缩放导航使其高度与内容div的高度相同?

How can I scale the navigation vertically so that its height is the same as the content div's height, no matter which page is loaded?

推荐答案

注意:此答案适用于不支持Flexbox标准的旧版浏览器.有关现代方法,请参见: stackoverflow/a/23300532/1155721

NOTE: This answer is applicable to legacy browsers without support for the Flexbox standard. For a modern approach, see: stackoverflow/a/23300532/1155721

我建议您看看等高列跨浏览器CSS且没有Hacks .

基本上,以与浏览器兼容的方式使用CSS做到这一点并非微不足道(但对于表而言却微不足道),因此请为自己找到合适的预打包解决方案.

Basically, doing this with CSS in a browser compatible way is not trivial (but trivial with tables) so find yourself an appropriate pre-packaged solution.

此外,答案取决于您是否要100%的高度或相等的高度.通常,它是相等的高度.如果高度为100%,答案会略有不同.

Also, the answer varies on whether you want 100% height or equal height. Usually it's equal height. If it's 100% height the answer is slightly different.

更多推荐

如何在不指定父级高度的情况下强制子级div为父级div的高度的100%?

本文发布于:2023-10-08 04:39:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471534.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:高度   为父   情况下   如何在   div

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!