改变页脚css的高度

时间:2013-06-30 01:37:48

标签: html css

问题:我不知道在使用reset.css时如何更改页脚的高度,页脚div的height属性不会改变任何内容。

您可以在本地克隆此内容并check it out here

HTML

<div class="wrapper">
    <p>Your website content here.</p>
</div>
<div id="footer">
    <p>&copy; 2013 Friend | Design and Development. All Rights Reserved.</p>
</div>

CSS - style.css

html, body {
    height: 100%;
    font-family: 'Arial', Helvetica;
}

.wrapper {
    min-height: 100%;
    height: auto !important;
    height: 100%;
    margin: 0 auto -4em;
}

#footer {
    background: #444444;
    height: 100px;
    font-family: 'Open Sans', sans-serif;
    color: #FFFFFF;
    padding: 20px;
}

RESET.css

/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}

/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}

3 个答案:

答案 0 :(得分:2)

如果您将.wrapper上的负底边距与页脚的高度相匹配,则应显示整个页脚。

或者,如果你想要一个漂浮在底部或页面的页脚,你可以这样做:

<div class="wrapper">
    <div class="content">
        <p>Your website content here.</p>
    </div>
    <div id="footer">
        <p>&copy; 2013 Friend | Design and Development. All Rights Reserved.</p>
    </div>
</div>

和css

.wrapper {
    min-height: 100%;
    position: relative;
}

.content {
    /* padding the footer adds 40 to footer height */
    padding-bottom: 140px;
}

#footer {
    position: absolute;
    bottom: 0;
    background: #444444;
    height: 100px;
    font-family: 'Open Sans', sans-serif;
    color: #FFFFFF;
    padding: 20px;
}

将高度与.content padding匹配

(未经测试,如果需要,我会弄它)

答案 1 :(得分:0)

当您定义页脚

时,您错过了d

http://plnkr.co/edit/ULC8NHYMqmP240OW2z1d?p=preview

答案 2 :(得分:0)

在Chrome 27中,.wrapper的下边距限制了#footer的可见高度。当height属性增加时,页脚确实变高,但额外高度(在4em值.wrapper之外)隐藏在初始视口高度之外。

所以,它的表现与指定完全相同:.wrapper占据了视口的底部4em以外的所有部分,#footer的高度与该4em无关。