Centering Div content

nmgod

New Member
Messages
2
Reaction score
0
Points
0
Been a while since I've made a website and I cant remember a browser safe way of centering a div, eg using say align="center" or whatever it is in IE will not work. Shouldn't be to hard to asnwer
 

techairlines

x10 Flyer
Community Support
Messages
2,867
Reaction score
165
Points
63
Use this:

Code:
<div style="text-align:center;">CENTERED CONTENT</div>

This is using CSS to apply center effects. You can also set CSS elements like:

Code:
.mycenteredcontent {
text-align:center;
}

Code:
<div class="mycenteredcontent">CENTERED CONTENT</div>
 
Last edited:

nmgod

New Member
Messages
2
Reaction score
0
Points
0
Is that not only text centering, by centering i meant, say having "body" div to have like a box in the center, not the content withing that div but the div itself
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
Almost every browser will understand the auto setting for a margin:

Code:
#div_id {
     width: 760px;
     margin: 0 auto;
     }

If you absolutely feel you need to fully support IE 6, then this hack will work:

Code:
#div_id {
     width: 760px;
     left: 50%;
     margin-left: -380px;
     }

Frankly, I'd let IE6 slide these days. Neither CSS hacks nor the available "IE-updating" javascript libraries are worth the bother for niggling little details like horizontal positioning of containers. Your site will still work without the hacks, even if it isn't exactly the same in IE6 as it is in other browsers. And it just may give people a reason to get fundamentally fed up with a browser that has been obsolete for many years.
 
Top