Click here to Skip to main content
15,886,562 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have entered this into my css file:
CSS
table{text-align:center;}

This is not centering the table:

ASP.NET
<table>
    <tr><td><h1>Text Here</td></tr>
    <tr><td><h1><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td></tr>

</td></tr></table>

I want css to be able to center like this:
ASP.NET
<center><table>
    <tr><td><h1>Text Here</td></tr>

    <tr><td><h1><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td></tr>

</td></tr></table></center>
Posted

text-align as it's name hints control the alignment of text only and not of other elements...
To center other elements you have to balance its margins...
CSS
.center {
    margin-left: auto;
    margin-right: auto;
}
HTML
<table class="center">
  ...
</table>/xml>
 
Share this answer
 
Not saying this is a good way of doing it.
Also all elements within body will be center aligned.
The display type of the table needs to be changed.
CSS
body{
  text-align:center;
}
table{
  display:inline-block;
}


Or div wrapper could be placed around the table like so.
CSS
div{
  text-align:center;
}
table{
  display:inline-block;
}

ASP.NET
<div>
<table>
    <tr><td><h1>Text Here</h1></td></tr>
    <tr><td><h1><asp:textbox id="TextBox1" runat="server" xmlns:asp="#unknown"></asp:textbox></h1></td></tr>
</table>
</div>
 
Share this answer
 

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