2015-11-06 421 views
0

我正在设计一个网站,其中顶部有一个toolbar,无论滚动如何,toolbar div始终位于顶部。这是我到目前为止有:html fixed div被其他div覆盖

http://jsfiddle.net/RjHMH/85/

<div class="stuckpart"> 
    <button type="button">this button is fixed</button> 
</div> 
<div id="table_div"></div> 

我使用google table JS库到table_div中附上一个表,但是当我向下滚动表时,button在顶部被重叠桌子。如何解决这个问题?

更具体一点:我想要的就是这个w3school做的,他们总是在顶部有一个工具栏。

我该如何实现这样的东西?在jsfiddle的小演示会很酷。

+1

'位置:固定;'是关键 – holden

+0

你还没有画出一幅非常清晰的图画。看看这个小提琴,让我知道这是你在找什么? http://jsfiddle.net/AKL35/958/ – Jase

+1

不要求在jsfiddle上的代码 - 代码应该在答案 - 你的代码也应该在问题中... – Soren

回答

2
.stuckpart{ 
     position:fixed; 
     padding-bottom: 200px; 
     z-index:100 
    } 

的z-index将解决您的重叠问题。

+0

虽然你吸... – byteBiter

0

这会将您的导航栏移动到页面的顶部,并在滚动页面时将其保留在那里。

<body> 
    <div id='nav_bar'> 
    </div> 
</body> 


#nav_bar { 
    position: fixed; 
    top: 0px; 
    //the rest of your nav bar style 
} 
0

HTML:

<div class="menu"></div> 

CSS:

.menu { 
    background-color: #000000; 
    width: 500px; 
    height: 50px; 
    position: fixed; 
    margin-top: 0px; 
} 

位置fixed是很重要的。

+0

固定元素的margin-top不重要... – CroaToa

1
#nav_bar { 
    position: fixed; 
    background-color:blue; 
    height:50px; 
    width:100% 
    } 
#content { 
    background-color:lightgreen; 
    overflow-y:auto; 
    height:200px; 
    position:relative; 
    width:100%; 
    top:50px; 
} 

http://jsfiddle.net/oa7mfcmb/6/

+0

它看起来不错,但请参阅这个http://jsfiddle.net/RjHMH/85/,你怎么解决这个问题? – byteBiter

+0

看起来不错,你可以upvote我的问题? – byteBiter