【问题标题】:How can I make a div with height 100% on css? [duplicate]如何在 CSS 上制作高度为 100% 的 div? [复制]
【发布时间】:2013-02-18 23:34:57
【问题描述】:

大家好! 我想让我的左侧菜单有 100% 的高度。

右侧会有一个内容区域,右侧也有一个页脚。

我希望左侧的浅蓝色菜单到达页面的底部 0。

检查这个 JSFiddle http://jsfiddle.net/mYw72/

或者这个代码!

        <div id="container">
        <div id="top">
            <div id="logo"></div>
            <div id="user-tools">
                <a href="#">Help</a>
                <span>&nbsp;|&nbsp;</span>
                <a href="#">Contact us</a>
            </div>
        </div>

        <div id="sidebar">
            <ul>
                <li><a href="#">Company</a></li>
                <li><a href="">Administrator</a></li>
                <li><a href="#">App</a></li>
                <li><a href="#">Configuration</a></li>
                <li><a href="#">Statistics</a></li>
                <li><a href="#">Monitor</a></li>
                <li><a href="#">Preference</a></li>
            </ul>
        </div>
        <div id="rightSide">
            <div id="content">
                Content.
            </div>

            <div id="bottom1">
                <div id="line-bottom"></div>
                <div id="text-bottom">Copyright 2012 <span>ME</span>, Inc. All Rights Reserved</div> 
            </div>
        </div>
    </div>

css 是这样的

html { 
padding:0px;
margin:0px;
}

body {
background-color: #ECEDEF;
font-family: Verdana, Tahoma, Sans-Serif;
color:#564b47;
padding:0px;
margin:0px;
}

#top {
background-image: url('../img/top.png');
background-repeat: repeat-x;
width: 100%;
height: 96px;
}

#rightSide{
overflow: hidden;
}

#sidebar{
position: relative; 
background:lightblue;
border-right:1.7px solid #FFFFFF; 
min-height: 100%;
line-height: 100%;
float: left; 
height:  100%;
margin-top: -5px;
}

#sidebar ul li {
list-style-type: square;
list-style-position: inside;
width:209px;
height:100%;
margin-top:15px;    
}
#sidebar ul li a{
list-style-position: inside;
display: block;
color:#3C3C3C;
text-decoration:none;
font-size:13px;
font-weight:bold;
padding:10px 20px 10px 40px;

}
#sidebar ul li a:hover {
color:#7da536;
width:209px;
border-right: 1.7px solid #ECEDEF;
background: #ECEDEF;
}
#sidebar ul li a:active{
background: #ECEDEF;
border-top: 1.7px solid #D8D9DB;
border-bottom: 1.7px solid #FFF;
border-right: 1.7px solid #FFF;
width:149px;

}

#content{
margin-left: 10px;

}

#bottom {
position: absolute;
bottom: 0;
background-color: #ECEDEF;
width: 100%;
padding: 53px 0 0 0;
}

#bottom1 {
position: absolute;
bottom: 0;
/*background-color: #ECEDEF;*/
background-color: greenyellow;
/*    width: 85.3%;*/
width: 100%;
padding: 53px 0 0 0;

/*    margin-left: 211px;*/
}

【问题讨论】:

  • 这应该让你更接近。将容器设置为绝对,子 div 设置为相对:jsfiddle.net/mYw72/1

标签: html css


【解决方案1】:
html, body, #container { height: 100% }

【讨论】:

  • 嗯,这成功了!谢谢!!
  • 没问题。为了将元素的高度设置为 100%,您需要确保其父元素的高度都为 100% 或设置的高度。包括html和body。
【解决方案2】:

您可以将左侧栏的高度设置为 100%,因为它里面的所有东西也都设置为 100% 的高度。

示例css:

html, body, #container{height:100%}
#sidebar{height:100%;}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-06
    • 2018-12-10
    • 1970-01-01
    • 2013-04-04
    • 2021-07-10
    • 2014-09-20
    相关资源
    最近更新 更多