center table in HTML

前端 未结 8 969
抹茶落季
抹茶落季 2020-12-03 08:53

How can I center the table within a div using html?

I have placed my content within a div tag and set the text-align

相关标签:
8条回答
  • 2020-12-03 09:12

    Add margin: 0px auto to your table tag

    0 讨论(0)
  • 2020-12-03 09:18
    <html>
    <body>
    <div style="text-align:center">
    <p>
        text test
    </p>
    <table border="1" style="margin: 0 auto;">
    <tr>
        <td>100</td>
        <td>200</td>
        <td>300</td>
    </tr>
    <tr>
        <td>400</td>
        <td>500</td>
        <td>600</td>
    </tr>
    </table>
    </div>
    </body>
    </html>
    
    0 讨论(0)
  • 2020-12-03 09:20

    Instead of <div style="text-align:center"> you could write <div style="width:600px;margin:0 auto">
    Which gives you a div with the width of 600 pixels and centers the div in the parent element.

    0 讨论(0)
  • 2020-12-03 09:24

    you can put the style in the table

    <table border="1" style="margin:0 auto;">
    

    However I do suggest that you use a style sheet and not inline styles

    0 讨论(0)
  • 2020-12-03 09:28

    Give width to table, and set margin auto horizontally.

    table {
      width:500px;
      margin: 10px auto;
    }
    
    0 讨论(0)
  • 2020-12-03 09:33

    Try the below

    <table style="margin:0px auto; width:500px">
    
    0 讨论(0)
提交回复
热议问题