Auto stretching vertical columns (divs)

2019-03-04 08:47发布

check this fiddle please:

I want the following: the red column has some text, the yellow is the dynamic content, the green has nothing, just a color. I want both red and green columns to be as height as the yellow content. height: 100% didnt work

4条回答
该账号已被封号
2楼-- · 2019-03-04 09:26

Working Demo

Not an easy solution but it works:

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:

#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;
}

Got it from here

查看更多
虎瘦雄心在
3楼-- · 2019-03-04 09:32

Try using a list instead.
You can display it as a table-row and the list-items as table-cells what makes all the list-items have the same height.

jsFiddle:

http://jsfiddle.net/Q7MFX/4/

Code:

<ul style="list-style:none;padding:0;display:table-row">
    <li style="display:table-cell;background-color: red;">11<br>11<br>11<br></li>
    <li style="display:table-cell;background-color: yellow;">22342<br>dsfsdf<br>sdfs df<br>v sdfsdf s dffffffffffffffff</li>
    <li style="display:table-cell;background-color: green; width: 40px;">11</li>
</ul>  
查看更多
Emotional °昔
4楼-- · 2019-03-04 09:36

You can use Jquery

http://jsfiddle.net/9XVSr/

html:

<div class="col" id="col1" style="background-color: red; float: left">11<br>11<br>11<br></div>
<div class="col" id="col2" style="background-color: yellow; float: left">22342<br>dsfsdf<br>sdfs df<br>v sdfsdf s dffffffffffffffff</div>
<div class="col" id="col3" style="background-color: green; width: 40px; float: right">11</div>

Jquery

$(document).ready( function() {
maxcol = Math.max($('#col1').height(),$('#col2').height(),$('#col3').height());
$('.col').height(maxcol);    
});
查看更多
贪生不怕死
5楼-- · 2019-03-04 09:40

You can use negative margins to achieve the result enter image description here

The floating divs should be wrapped in a container with overflow:hidden This is the fiddle This is the code

#container {
    overflow:hidden;
}

#container div {
    padding-bottom:2000px;
    margin-bottom:-2000px;
}
查看更多
登录 后发表回答