0

Hey guys was wondering .. i want my website to be aligned center so that all computers can view it.

like there is a lot of space wasted on the right as the site is aligned to the left..

how can i make it so that the site is in the center of the browser?

the default page size i am using is 1024x768(?) idk the second part after the 'x'

thanks :D

7
Contributors
6
Replies
8
Views
5 Years
Discussion Span
Last Post by almostbob
0

wrap a div around the entire page contents and in the CSS give it a width of 100% (so it fills the width of the screen). Then have a second div that specifies an actual width (how wide you want your content to be) and use the margin-left: auto; and margin-right: auto. This will center the inner div within the first. Place your content inside the second div.

<div id="page">
   <div id="container">
        your content goes here
   </div>
</div>

And your CSS:

#page {width: 100%;}
#container {
    width: 1024px; /* or whatever you need */
    margin-left: auto;
    margin-right:auto;
}

That should do the trick.

0

Warp the page contents in a DIV like below.

<div style="margin:0 auto; width:1024px;">Your Page Contents</div>

This should work.

0

use this

#wrapper{
          width:1000px;
          margin:0 auto;
}

<div id="wrapper">

</div>

when u use 1024px width its going to horizontal scroll bar for resolution 1024x768 so it is not right so whenever u use width for website use 1000px

Thanks & Cheers

Edited by Dani: Formatting fixed

0

better to use 960px width in the above code, to allow for all browser chrome and get it away from the very edges of the browser.

The two div answer above is wrong and unnecessary. The outer div (#page) doesn't do anything at all!

0

you may want to be carefull by setting a fixed width or height, since you have no idea who will visit the page and what resolution their screen/video card can support.

0

anything in pixels will fail ...
anything in any fixed size will fail ...
... in some/many/all combinations of device and browser.

current best practice for layout is em and % scalar dimensions that auto adjust to window size device resolution user preference,
added bonus that the site is disability friendly, auto adjusting around user preference, without further code.

a page laid oout (example)

body {width:95%; margin:auto;}
p { width:95%; margin:auto;}
p.this { width:85%; margin:auto;}
p.that { width:75%; margin:auto;}

looks the same at all resolutions, a html scrap

<body>
<div>bla bla bla</div><p>bla bla bla</p>
<p class='this'>bla bla bla</p>
<p class='that'>more  bla bla bla</p>

gives a similar indented paragraph structure in any browser,in partscreen or fullscreen

Edited by almostbob: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.