Html CSS多背景

Html CSS多背景,html,css,Html,Css,我有一个网站,我想改变它的背景。我想在顶部和底部加一个背景 以下是CSS代码: div.bg_top { background-image: url('bg_top.jpg'); background-repeat: no-repeat; background position: top center; } div.bg_bottom { background-image: url('bg_bottom.jpg'); background-repeat: no-repeat

我有一个网站,我想改变它的背景。我想在顶部和底部加一个背景

以下是CSS代码:

div.bg_top { background-image: url('bg_top.jpg'); background-repeat: no-repeat; background position: top center; } div.bg_bottom { background-image: url('bg_bottom.jpg'); background-repeat: no-repeat; background position: bottom center; } 分区背景图顶部{ 背景图片:url('bg_top.jpg'); 背景重复:无重复; 背景位置:上中; } 分区bg_底部{ 背景图片:url('bg_bottom.jpg'); 背景重复:无重复; 背景位置:底部中心; } HTML代码:

<div class="bg_top"> <div class="bg_bottom"> Content Here. </div> </div> 内容在这里。
正确吗?

如果您修复了以下问题,它应该可以工作:


我建议使用CSS速记作为最佳实践

.bg_top { background: url('bg_top.jpg') no-repeat top center; }

.bg_bottom { background: url('bg_bottom.jpg') no-repeat bottom center; } 

正如兰斯所说,只需将
背景位置:
更改为
背景位置:
就可以了


但我担心的是,你给背景的方式,不同的分辨率,两个背景图像可能会重叠,这会破坏所有的设计。因此,要使其与所有分辨率兼容,您需要选择任何其他选项。我建议使用任何图像编辑器,根据需要放置图像,制作一张图像,然后将该图像用作背景。

为了避免更改html,您还可以将一张背景放在
html
中,另一张放在
正文中。并使用最小高度(IE6的高度)以避免重叠。

实际上应为
中间顶部。水平的先,然后是垂直的。@DisgludedCoat-对不起,现在修好了。大多数浏览器都会以任意顺序正确呈现,因为这是一个常见的错误。你说得对-字符串值也是如此,因为没有歧义的可能(
top
显然是垂直的)。尽管顺序对数值至关重要,但使用速记并不能自动成为“最佳实践”。而且不用麻烦打开“it keep your stylesheet minger”参数。它可以帮助您快速找到CSS属性,使代码更可读,并在编辑时节省时间。如果这不是最好的做法,请告诉我梅塞克。
.bg_top { background: url('bg_top.jpg') no-repeat top center; }

.bg_bottom { background: url('bg_bottom.jpg') no-repeat bottom center; }