2010-11-08 32 views
0

有没有一种有效的方法来重叠2个div。CSS - 重叠 - 有效

我有以下,但无法使它们重叠。

#top-border{width:100%; height:60px; background:url(image.jpg) 0 0 repeat-x; float:left; position:relative;} 
#header-wrap{width:100%; height:80px; background:none; float:left;} 
#header{width:800px; margin:0 auto; height:80px; background:url(taller-image.jpg) 0 0 repeat-x} 



<div id="top-border"></div> 
<div id="header-wrap"> 
    <div id="header">links go here.</div> 
</div> 

这基本上给出了顶部横幅“突出”出来 但我无法让他们重叠的效果......

如在图像的顶部在这里看到:http://www.boguscreek.com/images/template.jpg

回答

1

位置:相对;左:-30px将在元件1

<style> 
    #div1{ 
     width:100px; height:100px; 
     border:1px solid red; 
     float:left; 
} 

#div2{ 
    width:100px; height:100px; 
    border:1px solid blue; 
    float:left; 
    position:relative; 
    left:-30px; 

}

移动element2的30个像素
</style> 

<div id="div1">1</div> 
<div id="div2">2</div> 
+0

我想在这里得到这个效果在网站的顶部:http://www.boguscreek.com/images/template.jpg – 2010-11-08 22:28:21

0

类似于重叠的我的图像模板看到的都是褐色的吧,但你并不需要使用重叠<div>的做这件事,只是图像与棕色的酒吧和蓝色的唯一的事马赛克作为<body>的背景图片,并将所有内容放在<div>的内部。

+0

我想避免巨大的图像文件,宁愿使用较小的图像重复-X。 – 2010-11-10 17:22:31

+0

我认为,你仍然可以使用我用平铺图像描述的方法。 – 2010-11-11 00:44:57