Replacement for <center> in CSS

D

Dennis Marks

What is the CSS command to center an element within a division. It is a
table so "text-align: center" does not work. If I do
<center><div>xxx</div></center> the table is centered. I would like a
CSS solution.
 
B

brucie

in post: <
Dennis Marks said:
What is the CSS command
^^^^^^^ property
to center an element within a division.

for inline elements e.g:

div{text-align:center}

<div>
<img ...>
</div>

for block level elements e.g:

table{width:50%;margin:auto;}

<div>
<table ...>
</div>

centering thingys
http://dorward.me.uk/www/centre/
http://www.w3.org/Style/Examples/007/center.html
http://www.student.oulu.fi/~laurirai/www/css/middle/
http://hicksdesign.co.uk/articles/css/vertical_centering_with_css/
 
N

Neal

What is the CSS command

CSS is a suggestion, not a command! User agents are NOT required to obey.
to center an element within a division. It is a
table so "text-align: center" does not work. If I do
<center><div>xxx</div></center> the table is centered. I would like a
CSS solution.

You have two solutions. Set the containing element to text-align: center;
or the contained block element to margin: 0 auto;

Pick the one which causes the least problems in your application. Usually
the first will work fine.
 
R

Richard

CSS is a suggestion, not a command! User agents are NOT required to obey.

Damn good way of spelling it out.
CSS is purely a compliment to the html language.
 
E

Els

Dennis said:
table {margin-left: auto; margin-right: auto;} works

IIRC you need text-align:center on the parent element too,
for IE5 or 5.5. I keep forgetting for which browser that is :-(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top