CSS div problems with position

CSS div problems with position

离不开的别离 发布于 2021-11-26 字数 1170 浏览 900 回复 2 原文

I have a css based asp.net masterpage. I am using a browse div located directly above a navigation div. The browse div is flowing down behind the navigation div. I did some playing around with the position and found that if i change the navigation position it fixes it, but everything in that div moves half way down the page. I have done some googleing and cant find anything about how to force a div to always be on top. If you need more info I can provide it.

I have pasted select parts of the css code below:

#header2 {
height: 2.5em;
border-bottom: 1px dashed #0055a5;
color: #FFF;
background-color: white;

#header2 .browse {
color: #000000;
background-color: transparent;
float: left;
margin-left: 1em;
margin-top: .1em;
font-style: normal;
font-variant: normal;
font-size: 70%;
line-height: normal;
font-family: Arial, Helvetica, Georgia, "Times New Roman", Times, serif;
width: 144px;
position: fixed;    

background-color: white;
width: 200px;
top: 105px;
left: 0em;
width: 13em;    
position: absolute;
font-family: Arial, Helvetica, sans-serif;

如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。



需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。


过气美图社 2022-06-07 2 楼

If you want it to stay fixed at the very top of the page, you could try setting top: 0; on the .browse class. Also see if it is the actual <div> tag that it is positioned vertically centered, or if it's just its contents.

I bet you'll save some time experimenting if you use firebug - go get it if you don't have it already =)

离旧人 2022-06-07 1 楼

By top, do you mean the top of the viewport, or top of the stack (i.e., z-index?).

If you mean top of the viewport, try position:fixed;

Edit, reading again, I think you mean z-index. Set the position of the element you want to keep on top (browse?) to relative, and then set the z-index to something like 100, i.e.,


that should do the trick.