Center browser upon viewing page

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
Jafil21
Forum Newbie
Posts: 13
Joined: Sun Oct 11, 2009 5:14 am

Center browser upon viewing page

Post by Jafil21 »

Hello everyone,

I'm looking for a way to implement the following requirement: Upon viewing a web page, which will host a very large background image (1900 by 1200 pixels wide), I want the visitor to be centered in the page. Which means, I want my webpage content to be placed at the center of the page in an imaginary (or, perhaps, not so imaginary) box and the browser's scrollbars to be adjusted relevantly.

Any way that I can achieve this?

Thank you.
User avatar
akuji36
Forum Contributor
Posts: 190
Joined: Tue Oct 14, 2008 9:53 am
Location: Hartford, Connecticut

Re: Center browser upon viewing page

Post by akuji36 »

Css can handle this for you. Create a class

for your image : decide on height and width and

centering:
in html

Code: Select all

 <html>
<head>
<style>
centerme {
   height:1900
   width:1700 
    margin-left: auto;
    margin-right: auto;
 
}
</style>
</head>
<body>
<img src="sunset.gif" class="centerme">
 
</body>
</html>
 
It may be easier if you set up a div and place pic inside div.
Then style div and style pic.

Take a look here:

http://www.w3.org/Style/Examples/007/center

thanks

Rod
Post Reply