儿童元素覆盖父元素

时间:2012-11-22 16:02:37

标签: html css

基本上我的网站布局方式,我有一些元素具有超出内容页面的全宽背景(例如导航栏背景完全穿过页面)。基本上我决定做的是在内容div中创建另一个div,并且对于它工作的导航栏,但是对于网站的下一部分,由于某种原因,子元素覆盖了所有浏览器中的父元素。我不明白为什么它似乎适用于导航栏部分。

这是CSS

#top-slider {
width:100%;
height:400px;
background: #222; /* Show a solid color for older browsers */
background: -moz-linear-gradient(#fefefe, #f1f1f1);
background: -o-linear-gradient(#fefefe, #f1f1f1);
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#fefefe), to(#f1f1f1)); /* older webkit syntax */
background: -webkit-linear-gradient(#fefefe, #f1f1f1);
-webkit-box-shadow: rgba(0, 0, 0, 0.4) 0px 1px 2px;
-moz-box-shadow: rgba(0, 0, 0, 0.4) 0px 1px 2px;
box-shadow: rgba(0, 0, 0, 0.4) 0px 1px 2px; 
float:left;
padding-bottom:20px;
position:relative;
width:980px;


}

#top-slider-full-bar {
position:absolute;
left:-9999px;
width:99999px;
background: #222; /* Show a solid color for older browsers */
background: -moz-linear-gradient(#fefefe, #f1f1f1);
background: -o-linear-gradient(#fefefe, #f1f1f1);
background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#fefefe), to(#f1f1f1)); /* older webkit syntax */
background: -webkit-linear-gradient(#fefefe, #f1f1f1);
-webkit-box-shadow: rgba(0, 0, 0, 0.4) 0px 1px 2px;
-moz-box-shadow: rgba(0, 0, 0, 0.4) 0px 1px 2px;
box-shadow: rgba(0, 0, 0, 0.4) 0px 1px 2px; 
height:400px;

}

以下是网站http://limerickchambers.hailstormcommerce.com,您可以看到,它似乎对导航栏工作正常... 我试过z-index,但似乎没有效果。 limerickchambers.hailstormcommerce.com

谢谢

1 个答案:

答案 0 :(得分:0)

考虑将您的html结构更改为以下内容:http://jsfiddle.net/KpTHz/

这样可以更容易管理。

<div class="outer">
 <div class="inner">HEADER</div>
</div>

<div class="outer">
 <div class="inner">CONTENT</div>
</div>

<div class="outer">
 <div class="inner">FOOTER</div>
</div>


.outer {
 width:100%;
 background:#ccc;
}

.inner {
 width:920px;
 background:#999;
 margin:0 auto 20px;
 padding:20px;
}