Center absolute position div in windowed mode?

185 Views Asked by At

I centered this absolute div:

<div style="
width:800px;
height:190px;
position:absolute;
left:50%;
margin-left:-400px;
border-width:10px;
border-style:solid;">
</div>

In maximized mode, it works normally. But when the width of the browser is smaller the div, I can't scroll to the left of the div, it was cut. I tested on Chrome and IE9

How can I center absolute div in windowed mode? What is the reason it is out of alignment?

1

There are 1 best solutions below

5
On

You'll probably want to change the div's width and height to percent values and then to center it, just do something like this:

top:0;
left:0;
right:0;
bottom:0;
margin:auto;
position:absolute;