2011-04-28 114 views
1

我有这样的:http://jsfiddle.net/WEyM9/如何定位一个元素相对于一个固定元素?

如何将我的相对.header DIV .content DIV位置(所以它不会去头之后)?如果没有在.content上设置固定的保证金顶部,可以这样做吗?

+0

z-index的是你的手段? – 2011-04-28 11:55:53

+0

为什么你不能使用固定的“margin-top”? – thirtydot 2011-04-28 11:58:16

+0

@Davood Jafari我不明白z-index如何解决这个问题,请您详细说明一下吗? – 2011-04-28 11:58:30

回答

3

可能对你有一个解决方案,但你需要一个额外的包装:

HTML:

<div class="wrapper"> 
    <div class="header"> 
      header 
    </div> 
    </div> 

    <div class="content"> 
     content 
    </div> 

CSS:

.wrapper { 
width: 400px; 
position:relative; 
height: 80px; 
} 

.header { 
    width: 400px; 
    background-color: green; 
    height: inherit; 
    position: fixed;  
} 

.content { 
    width: 400px; 
    background-color: magenta; 
    height: 400px; 
} 
+0

真棒,thx! – 2011-04-28 12:34:23

+0

yw :)希望它有帮助 – 2011-04-28 12:37:24

相关问题