You must Sign In to post a response.
  • Category: ASP.NET

    How to align table in center

    i want to align my table in center inside a div. I can't write like this <table align=center>.iam not getting center in design
  • #767263
    try using below CSS

    #div {
    display: flex;
    justify-content: center;

    #table {
    align-self: center;
    //or you can use Wrapper DIV as below
    < div id="content">
    < div id="wrapper">
    < table>...< /table>
    < /div>
    < /div>

    To position horizontally center you can say width: 50%; margin: auto;. As far as I know, that's cross browser. For vertical alignment you can try vertical-align:middle;, but it may only work in relation to text. It's worth a try though.

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #767269
    Hello Krishna

    try this

    < div id="content">
    < div id="wrapper">
    < table>...< /table>
    < /div>
    < /div>

  • #767288

    You can try this below css property to align the table in center.

    < div>
    < table>
    < tr>
    < th>Name</th>
    < th>Mobile No</th>
    < th>Country</th>
    < /tr>
    < /table>

    < /div>
    < style>
    margin-left: 42%;
    border: 2px solid red;
    < /style>

    Sridhar Thota.
    Editor: DNS Forum.

  • #767295

    May be because of your DIV it is not center aligned, if your div any one of the property is not supported for center aligned i.e. if your div align is left and your table align is center then it won't be aligned center because it inherited parent (div) properties too, so make sure about div properties too, and try the same in your browser that will help you...

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

Sign In to post your comments