Guesser
Guesser

Reputation: 1857

Positioning div in center of window (vertically)

I'm using this CSS to postion a div horizontally and vertically to the window which works fine until you scroll down the page, then the div remains in the same centred position as if the page hadn't been scrolled.

width:600px;
height:300px;
position:absolute;
left:50%;
top:50%;
margin:-150px 0 0 -300px;
z-index:99;

Can this be done using CSS?

Upvotes: 0

Views: 186

Answers (3)

Ümit KOL
Ümit KOL

Reputation: 31

Try the following CSS: position:fixed;

Upvotes: 0

gherkins
gherkins

Reputation: 14983

Take a look at:

http://www.w3schools.com/cssref/playit.asp?filename=playcss_position&preval=fixed

position: fixed; might be what you're looking for.

Upvotes: 0

Some Guy
Some Guy

Reputation: 16210

That's because your position is absolute!

You should try using position: fixed; instead.

Upvotes: 2

Related Questions