Search code examples
javascriptcssresizepositioning

How to center a user's view using javascript


I have a webpage with a background image that extends (in some resolutions) beyond the width of the browser's window.

The contents of the webpage in question are centered, relative to the background image, and so I would like that the visitors to the webpage would have their view horizontally centered aswell.

Is that possible? If not, how would I go with dynamically cropping the background image, to fit the window size of the viewer?


Solution

  • Modify the css:

    Goto the body{} class and modify it as:

    body
    {
    background: url('path-to-ur-image/image.jpg') top no-repeat;
    }