0

Is it possible to centre a div that is larger than the viewport using jquery so that its always centered regardless of re-size?

I have a jquery slider which is 2000px wide that I need to centre so that the central content always displays within the 1000px main content frame - regardless of screen size..

Dancer
  • 17,035
  • 38
  • 129
  • 206

1 Answers1

1

Quite possible by setting it's "left" to 50% and it's "margin-left" to half of it's size in pixel.

http://jsfiddle.net/sbUXr/

<div style="position:absolute;width:300px; height:300px; left:50%; margin-left:-150px; border:2px solid red;">
    <div style="position:relative;width:100%;height:100%;">
        <div style="position:absolute;left:50%;top:100px;width:400px;height:100px;margin-left:-200px;border:2px solid green;">

        </div>
    </div>
</div>
Chris S.
  • 1,199
  • 11
  • 25