Div Align In CSS?

SpaceshipSpaceship
Spacemail by SpaceshipSpacemail by Spaceship
SpaceshipSpaceship
Watch
Impact
200
What's the best way (well, most simplest :D ) to achieve a centralized layout using CSS?

I've been playing around with 'right', 'left' and 'position' but it's starting to get a little confusing...

Is it normal to just place everything between a div align tag or is there a proper CSS method of doing it?

Thanks in advance, I really do appreciate the help! :xf.love:
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Make a wrapper div and set the left and right margins to "auto".

In the stylesheet:
Code:
...
#wrapper {margin:0 auto;}

...
HTML:
<body>
<div id="wrapper">
rest of your page goes here
</div>
</body>

That will center your entire page on the screen. To center divs within it, do the same thing. Don't use "align=center" unless you're using a transitional doctype - it's deprecated.

To center some text within another element, apply the css code text-align:center to the enclosing element (p, td, div, whatever).
 
Last edited:
1
Close
Thanks, it worked. :D +repped.
 
0
Close
enlytend said:
Make a wrapper div and set the left and right margins to "auto".

In the stylesheet:
Code:
...
#wrapper {margin:0 auto;}

...
HTML:
<body>
<div id="wrapper">
rest of your page goes here
</div>
</body>

That will center your entire page on the screen. To center divs within it, do the same thing. Don't use "align=center" unless you're using a transitional doctype - it's deprecated.

To center some text within another element, apply the css code text-align:center to the enclosing element (p, td, div, whatever).

That's correct. I always use margin: auto auto; though, it works better with alternative screen layouts suchs as cellphones and weird screen resolutions, but "0 auto;" is always a safe bet for common resolutions
 
0
Close
remember you mus always have a <!DOCTYPE tag, for the margins to work correctly on all browsers
 
0
Close
CatchedCatched

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back