全屏背景与粘性页脚一起使用?
我正在使用本教程创建全屏背景。 (更新:对图像使用 100% 的高度和宽度不是我想要的,因为这只是拉伸图像,此脚本保持纵横比。)
我还尝试合并粘性页脚使用本教程。
添加粘性页脚部分会在背景图像上创建一些额外的水平滚动。
我的图像为 700 像素 x 466 像素,浏览器窗口为 1240 x 1414。我的网站水平位于浏览器窗口的中间,但可以在右侧进行额外的滚动。
如何使全屏背景图像与粘性页脚一起使用,以便消除额外的水平滚动?粘性页脚需要位于背景图像的顶部而不是下方。
更新:使用 Supr 的答案来解决水平问题,唯一需要解决的是页脚位于背景图像下方而不是其上方。
这是我的css:
* {
margin:0;
}
html, body {
height:100%;
}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -4em;
}
.footer, .push {
height: 4em;
}
.clear {
clear:both;
}
body {
font-size: 62.5%; /* Resets 1em to 10px */
background-repeat:repeat-x;
background-image: url('images/background-repeat.jpg');
margin:0px;
}
#body {
width:1000px;
margin:0 auto 0 auto;
}
.fullBg {
position: absolute;
top: 0;
left: 0;
overflow: hidden;
}
#maincontent {
position: absolute;
top: 0;
left: 0;
z-index: 50;
}
这是我的html:
<div class="wrapper">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/bg1.jpg" alt="" id="background">
<div id="maincontent">
<div id="body"></div>
<div class="push"></div>
</div>
<div id="footer">
<p><a href="/home" title="Home">Home</a> | <a href="/about" title="About">About</a></p>
</div>
</div>
I'm using this tutorial to create a full screen background. (UPDATE: Using height and width at 100% for the image is not what I want as that just stretches an image, this script keeps the aspect ratio.)
I'm also trying to incorporate a sticky footer using this tutorial.
Adding the sticky footer part is creating some extra horizontal scrolling on the background image.
My image is 700px x 466px and my browser window is 1240 x 1414. My website sits in the middle of the browser window horizontally but there's an extra bit of scrolling that can be done to the right.
How can I get the full screen background image working with the sticky footer so that it removes the extra horizontal scrolling? The sticky footer needs to sit on top of the background image not below it.
UPDATE: Using Supr's answer to solve the horizontal problem, the only thing left to solve is that the footer sits below the background image rather than on top of it.
This is my css:
* {
margin:0;
}
html, body {
height:100%;
}
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -4em;
}
.footer, .push {
height: 4em;
}
.clear {
clear:both;
}
body {
font-size: 62.5%; /* Resets 1em to 10px */
background-repeat:repeat-x;
background-image: url('images/background-repeat.jpg');
margin:0px;
}
#body {
width:1000px;
margin:0 auto 0 auto;
}
.fullBg {
position: absolute;
top: 0;
left: 0;
overflow: hidden;
}
#maincontent {
position: absolute;
top: 0;
left: 0;
z-index: 50;
}
Here's my html:
<div class="wrapper">
<img src="<?php bloginfo('stylesheet_directory'); ?>/images/bg1.jpg" alt="" id="background">
<div id="maincontent">
<div id="body"></div>
<div class="push"></div>
</div>
<div id="footer">
<p><a href="/home" title="Home">Home</a> | <a href="/about" title="About">About</a></p>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
添加页脚会导致水平滚动吗?只是一个未经测试的想法,但请尝试添加
,
以防万一有东西(边距/填充)溢出到页脚之外。
Adding the footer is causing horizontal scrolling? Just an untested idea, but try adding
and possibly
in case there is something (margin/padding) overflowing outside the footer.
如果没有看到您的代码,就很难回答,但在 firebug/webkit 开发人员工具中,请检查 html 和 body 元素以及包装内容的任何其他元素上的 css 溢出和其他显示属性。那里可能有一个溢出:自动,需要设置为溢出:隐藏;
Without seeing your code it's difficult to answer, but in firebug/webkit developer tools check the css overflow and other display properties on the html and body elements, and any other elements that wrap your content. It's probable there's an overflow: auto in there which needs setting to overflow:hidden;
啊?你为什么要这么麻烦?您没有提供任何分析代码,但我想您正在寻找类似的东西:
或者不使用 CSS3 的替代方案,以实现 IE8 兼容性:
加上 html:
Huh? Why are you going to that much trouble? You haven't given any code for analysis, but I presume you're after something like:
Or an alternative that doesn't use CSS3, for IE8 compatibility:
Plus html:
尝试这个伙伴的身体元素,
Try this mate for body element,