Auto stretching vertical columns (divs)

∥☆過路亽.° 提交于 2019-12-02 20:40:09

问题


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


回答1:


You can use negative margins to achieve the result

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



回答2:


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:


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>  



回答4:


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


来源:https://stackoverflow.com/questions/16545531/auto-stretching-vertical-columns-divs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!