Unstoppable Domains

Div Align In CSS?

Spaceship Spaceship
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
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
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
•••
Thanks, it worked. :D +repped.
 
0
•••
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
•••
remember you mus always have a <!DOCTYPE tag, for the margins to work correctly on all browsers
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back