简体   繁体   English

网站顶部和底部的背景图像是否分开?

[英]Separate background images at top and bottom of site?

I'd like to have separate background images on the top and bottom of my site but can't quite seem to nail it. 我想在网站的顶部和底部放置单独的背景图片,但似乎不太满意。 I would like the images to stay at the absolute top and bottom of the page.Below is a shot of the site mockup, and a shot of the backgrounds on their own with dimensions. 我希望图像保留在页面的绝对顶部和底部。以下是网站模型的快照,以及背景本身的尺寸。

The mockup doesn't show it, but there will be text links and copyright info at the bottom. 样机未显示,但底部将有文本链接和版权信息。 You can find my failed attempt at coding at www[dot]dev[dot]arbitersoflight[dot]net 您可以在www [dot] dev [dot] arbitersoflight [dot] net上找到我的编码失败尝试

Mockup img683[dot]imageshack[dot]us/img683/4502/mocky[dot]jpg 样机img683 [dot] imageshack [dot] us / img683 / 4502 / mocky [dot] jpg

Backgrounds img233[dot]imageshack[dot]us/img233/1293/94210454[dot]jpg 背景img233 [dot] imageshack [dot] us / img233 / 1293/94210454 [dot] jpg

Note: The backgrounds are 1200x400 each. 注意:每个背景均为1200x400。

EDIT: At this point I can get the two images to show up without fail, the problem is getting the bottom image to stick to the absolute bottom of the browser window. 编辑:在这一点上我可以使两个图像显示出来,没有问题,问题是使底部的图像坚持到浏览器窗口的绝对底部。 It seems that it is currently at a fixed position. 看来它目前处于固定位置。 Below is my CSS and HTML.. 以下是我的CSS和HTML。

UPDATE (Solved): I finally solved this by reworking my code based on this guide: http://ryanfait.com/resources/footer-stick-to-bottom-of-page/ Thanks for all of the suggestions everybody. 更新(已解决):我终于根据此指南对代码进行了重新设计,以解决此问题: http : //ryanfait.com/resources/footer-stick-to-bottom-of-page/感谢大家的所有建议。

Another thing you can do is set a background image on the body and on html. 您可以做的另一件事是在正文和html上设置背景图像。

body {
    background: url(...);
}

html {
    background: url(...);
}

You can see jqueryui.com for an example of this. 您可以查看jqueryui.com以获得此示例。

You could use the second image as the body background, set a color too, and the first image as the container's background. 您可以将第二张图像用作主体背景,也可以设置颜色,而将第一张图像用作容器的背景。 Or vice-versa, but remember to align the background, and if you switch, mind the container's height. 反之亦然,但要记住调整背景,如果要切换,请注意容器的高度。

The body and html background (like the suggestions from zzzzBov and nemophrost) don't work in my Firefox... 正文和html背景(例如zzzzBov和nemophrost的建议)在我的Firefox中不起作用...

body {
    background: #DDD url('2.png') no-repeat center bottom;
}
.container {
    background: url('1.png') no-repeat center top;
}

What you can do: 你可以做什么:

The menu is a div with an own background to fit the upper area. 菜单是一个具有自己背景的div以适合上方区域。 Then apply the background with the bottom part to the body or content/page container that you are using. 然后将底部带有背景的内容应用于您正在使用的正文或内容/页面容器。

It sounds like you want: 听起来像您想要的:

html
{
  background: url(...) no-repeat top; /* see the background-position property */
}

body
{
  background: url(...) no-repeat bottom;
}

you may want to switch one or both to use repeat-x , and make sure you set a suitable background color to match the color on the images. 您可能要切换一个或两个都使用repeat-x ,并确保设置合适的背景色以匹配图像上的颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM