html - 当 parent 使用背景大小 :cover 时如何定位页脚

标签 html css

我有一个页面,其正文使用 background-size:cover with an image。我希望我的页脚留在页面底部(不粘;就在页面底部)。问题是页脚只停留在原始图像大小的底部,因此当窗口的大小调整为大于原始图像大小时,页脚保持在原位,并在其下方留有边距。我尝试了很多事情都没有成功。这是我的 html:

<body>
<form runat="server">
    <div class="contr"><div class="g01"></div></div>
        <asp:ContentPlaceHolder ID="MainContent" runat="server" />
        <div style="clear: both;"></div>
        <div class= "footer"></div>
</form> 
</body>

然后是我的风格规则:

body   
{
font-size: .80em;
font-family: "Helvetica Neue", "Lucida Grande", "Segoe UI", Arial, Helvetica, Verdana, sans-serif;
margin: 0px;
padding: 0px;
background: url(hex2.png) no-repeat center center fixed; 
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
 background-size: cover;
 filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='.hex2.png', sizingMethod='scale');
-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='.hex2.png', sizingMethod='scale')";
min-height:100%;
}

.footer 
{
width:94%;
height:123px;
background: url(lines.png); 
position: relative;
bottom: 0;
}

最佳答案

我在正文中使用 background-size: cover 的页面中实现了页脚,但没有遇到问题。

HTML:

<div id="container">
    <h1>Lorem Ipsun</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
<div id="footer">
    <p>Footer</p>
</div>

CSS:

html {
    height: 100%;
}

body {
    height: 100%;
    margin: 0px;
    background: url(image.jpg) no-repeat center center fixed;
    background-size: cover;
}

#container {
    height: 100%;
}

#footer {
    background: orange;
    height: 100px;
    margin-top: -100px;
}

LIVE DEMO

这对你有用吗?

关于html - 当 parent 使用背景大小 :cover 时如何定位页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21613465/

相关文章:

CSS 光标放大/缩小

css - 带切割三 Angular 形的矩形

Cargo Collective 站点的 jQuery 实现

javascript - 停止表单请求,直到 ajax 请求完成

html - 如何使 flex 和 svg 在 safari 和 IE11 中工作

javascript - 如何使用 jquery 在浏览器中获取我的网站打开的选项卡数量?

android - 自定义字体(woff2)在使用 Visual Studio Community 和 Cordova 制作应用程序的 Android 中不起作用

html - 具有内部位置的有序列表中第二行的跨浏览器缩进 - 不可能?

javascript - polymer/深度/选择器在移动设备中不起作用

CSS3 过渡不起作用