简体   繁体   English

并排在容器中填充高度

[英]Side by side divs filling height in container

I've got a set of side by side divs (actually using HTML5 sections but I'm assuming the solution and behavior is just the same). 我有一组并排的div(实际上使用HTML5部分,但我假设解决方案和行为是一样的)。 They sit in a container with the right side holding form fields and left side a summary title and information. 他们坐在一个容器中,右侧拿着表格字段,左侧是摘要标题和信息。 The structure looks something like this: 结构看起来像这样:

<div id="container">
    <div id="left" >Summary here</div>
    <div id="right">Form fields here</div>
</div>

The catch is I have to hide or show various fields depending on actions taken with javascript so the actual height of the right side and container are not static. 问题是我必须隐藏或显示各种字段,具体取决于使用javascript采取的操作,因此右侧和容器的实际高度不是静态的。 What I need is to get the left side to fill the height of the container so it will match the right. 我需要的是让左侧填充容器的高度,使其与右侧相匹配。 I've tried the numerous solutions on the internet but none seem to be working. 我在互联网上尝试了很多解决方案,但似乎都没有。

Thanks in advance! 提前致谢!

This is a very common question. 这是一个非常常见的问题。 Take a look at this article... it has all the answers: 看看这篇文章......它有所有的答案:

http://matthewjamestaylor.com/blog/equal-height-columns-cross-browser-css-no-hacks http://matthewjamestaylor.com/blog/equal-height-columns-cross-browser-css-no-hacks

Now, here's a quick fiddle of putting that to use. 现在,这是一个使用它的快速小提琴。 Try clicking on any of the "Column #" text elements to remove them from the document... the columns will resize nicely :) 尝试单击任何“Column#”文本元素将其从文档中删除...列将调整大小:)

http://jsfiddle.net/UnsungHero97/qUT3d/9/ http://jsfiddle.net/UnsungHero97/qUT3d/9/

HTML HTML

<div id="container3">
    <div id="container2">
        <div id="container1">
            <div id="col1">Column 1</div>
            <div id="col2">Column 2</div>
            <div id="col3">Column 3</div>
        </div>
    </div>
</div>

CSS CSS

#container3 {
    float:left;
    width:100%;
    background:green;
    overflow:hidden;
    position:relative;
}
#container2 {
    float:left;
    width:100%;
    background:yellow;
    position:relative;
    right:30%;
}
#container1 {
    float:left;
    width:100%;
    background:red;
    position:relative;
    right:40%;
}
#col1 {
    float:left;
    width:26%;
    position:relative;
    left:72%;
    overflow:hidden;
}
#col2 {
    float:left;
    width:36%;
    position:relative;
    left:76%;
    overflow:hidden;
}
#col3 {
    float:left;
    width:26%;
    position:relative;
    left:80%;
    overflow:hidden;
}​

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM