extend floated menu, so height is matching the content div

我只是一个虾纸丫 提交于 2019-12-12 01:57:33

问题


I have a content div and a sidebar, the content div's height will adjust depending on the content being loaded, but I want the sidebar div to be extended all the way down, depending on the max size of the content, the sidebar should be the same size.

Fiddle, Fiddle, Fiddle! - JS Fiddle

View the above fiddle, I want the sidebar extended all the way down, depending on the height of the content div.

For non fiddlers:
CSS

#content
{
border:1px solid black;
float: left;
width: 80%;
}

#sidebar
{
width: 19%;
border:1px solid red;
float: left; 
background-color: #ddd;
}

p{text-align: right}

HTML

<div id="container" style="background-color: #f2f2f2">
<div id="content">Here is the content, the height of this div will vary depending on the content.
    <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
    <p>I dont want this big empty box. --> <br/>I want the sidebar extended down here--></p>
</div>
<div id="sidebar">I want this sidebar to extend ALL the way down, to match the #content divs height (whatever it is, dynamic)</div>
<div style="clear:both"></div>


回答1:


You will have to use javascript for that. with Jquery it will be somehing like following.

    $('#sidebar').height($('#content').height());

fiddle http://jsfiddle.net/YMFGU/9/



来源:https://stackoverflow.com/questions/7434635/extend-floated-menu-so-height-is-matching-the-content-div

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