无论我做什么,我的div都不想成为100%身高......:/

时间:2014-10-16 15:01:09

标签: html css

编辑:我发现由于一些奇怪的原因,我的#content继承了一个height属性。我不知道为什么,或者为什么要覆盖我试图设定的高度。 :/

我做了很多关于这方面的研究,但我对css还不是很好,所以我似乎无法弄明白。我正在为一个uni项目建立一个小网站,一切正常,除了一件事。内容div只是不想填写我告诉它的高度。

    <body>
    <div id="container">
        <div class="logo"><img src="/Users/sophie/Dropbox/3 Uni/MultiEngI/Aufgabe 1/Acc/ArtArchiveLogo500.png" alt="ArtArchive" /></div>
        <div class="header">ArtArchive</div>
        <div id="nav"><li>
            <ul>
                <a href="#">Upload</a>
            </ul>
            <ul>
                <a href="#">Organize</a>
            </ul>
            <ul>
                <a href="#">Browse</a>
            </ul>
        </li>
        </li></div>
        <div id="content" style="height:100%;">I am empty :(</div>
        <div class="footer">I am empty :(</div>
    </div>  
</body>

这是html部分,而css:

    .header {
    background:#c61350;
    height: 100px;
    line-height: 100px;
    text-align: center;
    padding:10px;
}

    .header {
    border-bottom: 12px solid #cd365b;
    color: white;
    font-size: 36px;
    font-family: 'Lato',arial,sans-serif;
    letter-spacing: 50px;
}

    #content {
    height : auto !important; 
    height : 100%;            
    min-height : 100%; 
    background: #fff;
    width: 60%;
    overflow: auto;
    left:0;
    right:0;
    margin-left:auto;
    margin-right:auto;
    padding:10px;
    padding-bottom:80px;   /* Height of the footer element */
}
.footer {
    width:100%;
    height:80px;
    position:absolute;
    bottom:0;
    left:0;
    background:#5f4e54;
}

具有id内容的div应该是100%高度而不是。 感谢您阅读:)

1 个答案:

答案 0 :(得分:5)

您正在声明height : auto !important;!important声明优先于其他相同的样式属性。只需删除它:

#content {
    height: auto; 
    height: 100%;            
    min-height : 100%; 
    ...
}

请注意,您的#content元素将是其#container父级的高度的100%。如果您的#container元素本身没有高度,则您的#content元素也没有高度。您可能希望使用vh单位。如果是这种情况,请在此处查看我的其他答案:Make div 100% height of browser window

相关问题