Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I center a table using CSS?

In Site.css
XML
.centering{margin-left:auto;margin-right:auto;}

Default.aspx
XML
<table class="centering">
...
</table>
Posted
Comments
Sergey Alexandrovich Kryukov 8-Apr-15 10:58am    
What goes wrong here?
It should work, but can be spoiled by some other style definitions. Please see my answer.
—SA

1 solution

The idea is correct, but first thing you should care of is the width. First of all, the element may take the whole width of the page or parent element. Say, you can inherit it from your more general table style. In this case, you center, but you need a room to center in. So, make sure the element to be centered is limited in width. It could be defined by content of the table (default), or you can use percentage.

Please see: http://webdesign.about.com/od/beginningcss/a/aa012207.htm.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900