Html 页面底部的粘性页脚和正文背景图像
我有HTML5样板,我想做一个以粘性页脚和图片为背景的模板。背景应始终位于页面的末尾(如果页面高于clientHeight)或屏幕上(如果页面较短)。Html 页面底部的粘性页脚和正文背景图像,html,css,background-image,sticky-footer,background-position,Html,Css,Background Image,Sticky Footer,Background Position,我有HTML5样板,我想做一个以粘性页脚和图片为背景的模板。背景应始终位于页面的末尾(如果页面高于clientHeight)或屏幕上(如果页面较短)。 我的问题是当粘性页脚工作,但背景不工作,反之亦然 请看一看 这是我的index.html: <body> <div class="wrap"> <header></header> <div class="main clearfix right-sideb
我的问题是当粘性页脚工作,但背景不工作,反之亦然 请看一看 这是我的index.html:
<body>
<div class="wrap">
<header></header>
<div class="main clearfix right-sidebar">
<div class="content"></div>
<div class="sidebar"></div>
</div>
</div> <!-- end of .wrap -->
<footer></footer>
</body>
我的CSS是:
/*html, body { min-height: 100%;}*/
html, body { height: 100%;}
body > .wrap {height: auto; min-height: 100%; margin: 0 auto;}
body > .wrap > .main { padding-bottom: 70px;}
body > .wrap, body > footer {width: 950px; position: relative;}
body > footer { margin: -70px auto 0 auto ; height: 70px; clear:both; }
</* end of centered sticky footer */
body { background: url(../img/bg.png) #fff 0% 100% repeat-x; }
.clearfix:before, .clearfix:after { content: " "; display: table;}
.clearfix:after { clear: both; }
.clearfix { *zoom: 1; }
/*html,正文{最小高度:100%;}*/
html,正文{高度:100%;}
body>.wrap{高度:自动;最小高度:100%;边距:0自动;}
body>.wrap>.main{填充底部:70px;}
正文>包裹,正文>页脚{宽度:950px;位置:相对;}
正文>页脚{页边距:-70px自动0自动;高度:70px;清除:两者;}
您可以使用jQuery将body min height设置为屏幕大小,并将其从页脚高度偏移
$('document').resize(function(){
var windowHeight = $('window').height() - $('footer').height();
$('.wrap').css('min-height', windowHeight );
});
您可以尝试使用本教程中没有js的Sticky footer:我自己用body解决方案解决了这个问题,因为我找不到任何其他解决方案。我将我的背景图像设置为主体,它也位于页脚后面。我想不出其他解决方案,因为您实际上在页面包装器外放置了一个div:
body{
width:100%;
background: url(../images/lines.png);
background-repeat: repeat-y;
background-position: center center;
}
当然可以,但我不想。我仍然相信我只能用CSS来做。不管怎样,谢谢你的回复。它不起作用。参见示例:您可以添加内容或更改窗口大小以查看:我不喜欢z-index
解决方案。你的想法需要一个额外的标签。我觉得这样做更好:它有一个额外的父div.bg
。唯一的一个不便是div.bg
必须是透明的,如果您想显示身体背景图像(例如在页面顶部)。然而,我仍然在寻找一个不需要任何额外html元素的方法。当做