Center image in table td in CSS

前端 未结 9 790
萌比男神i
萌比男神i 2021-01-30 19:35

I\'ve been trying to align an image to the center of the table td. It worked with setting margin-left to a specific value but it also increased the size of td too and that isn\'

相关标签:
9条回答
  • 2021-01-30 20:00
    <table style="width:100%;">
    <tbody ><tr><td align="center">
    <img src="axe.JPG" />
    </td>
    </tr>
    </tbody>
    </table>
    

    or

    td
    {
        text-align:center;
    }
    

    in the CSS file

    0 讨论(0)
  • 2021-01-30 20:04

    Another option is the use <th> instead of <td>. <th> defaults to center; <td> defaults to left.

    0 讨论(0)
  • Simple way to do it for html5 in css:

    td img{
        display: block;
        margin-left: auto;
        margin-right: auto;
    
    }
    

    Worked for me perfectly.

    0 讨论(0)
提交回复
热议问题