Sudantha
Sudantha

Reputation: 16224

Positioning a DIV tag in top of the page

I need to Positioning a DIV tag in top of the page like in the StackEchange top menu bar

i used to following code but there is the space

div.topbar{
    width:100%;
    background:#C0C0C0;
    border:1px;
    border-color:gray;
    border-style:solid;
    text-decoration:none;
    font-family:Arial;
    top:auto;
}

Upvotes: 1

Views: 34122

Answers (4)

Agos
Agos

Reputation: 19450

position: absolute is not needed if is the first child of the containing element. Just do a

margin: 0
padding: 0

and you'll have the added benefit of the next element in the flow positioned correctly after and not under the top bar.

Upvotes: 2

mmieluch
mmieluch

Reputation: 435

You also need to add:

position: absolute;
top: 0px;

Upvotes: 7

Fermin
Fermin

Reputation: 36111

add

div.topbar{
  position:absolute;
  top:0
}

Upvotes: 1

fmt
fmt

Reputation: 993

Did you try adding position:absolute; and top:0;?

You may need to clear:both; the next element, though.

Upvotes: 0

Related Questions