Html 使垂直菜单高度适合 100%

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22654776/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:22:50  来源:igfitidea点击:

Make vertical menu height fit 100%

htmlcss

提问by Optimus Prime

I did a sketch http://i.imgur.com/cx3jXPu.jpgso sidebar has to drag down all the way together with the content sidebar.

我做了一个草图http://i.imgur.com/cx3jXPu.jpg所以侧边栏必须与内容侧边栏一起向下拖动。

回答by Ahmedskaya

its height should be 100% as well as all of its parents divs

它的高度应该是 100% 以及它的所有父 div

html, body{
    height:100%;
    width: 100%;
}
.container{
    width:100%;
    height:100%;
    border:1px solid red;
}
.sidebar{
    width:25%;
    height:100%;
    background:gray;
}

http://jsfiddle.net/ahmedskaya/Bek9L/1863/

http://jsfiddle.net/ahmedskaya/Bek9L/1863/

回答by Kheema Pandey

Using a jquery you can achieve it easily.

使用 jquery 可以轻松实现。

$(document).ready(function(){
    $("#side").height( $("#main").height() );
});

Here is CSS also.

这里也是 CSS。

#side{background: gold;}
#side, #main{float:left; width:200px;}

Here is the Demo.

这是演示