Center image in table td in CSS

前端 未结 9 789
萌比男神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 19:39

    Center a div inside td using margin, the trick is to make the div width same as image width.

    <td>
        <div style="margin: 0 auto; width: 130px">
              <img src="me.jpg" alt="me" style="width: 130px" />
        </div>
    </td>
    
    0 讨论(0)
  • 2021-01-30 19:41
    <td align="center">
    

    or via css, which is the preferred method any more...

    <td style="text-align: center;">
    
    0 讨论(0)
  • 2021-01-30 19:46

    This fixed issues for me:

    <style>
    .super-centered {
        position:absolute; 
        width:100%;
        height:100%;
        text-align:center; 
        vertical-align:middle;
        z-index: 9999;
    }
    </style>
    
    <table class="super-centered"><tr><td style="width:100%;height:100%;" align="center"     valign="middle" > 
    <img alt="Loading ..." src="/ALHTheme/themes/html/ALHTheme/images/loading.gif">
    </td></tr></table>
    
    0 讨论(0)
  • 2021-01-30 19:47

    Set a fixed with of your image in your css and add an auto-margin/padding on the image to...

    div.image img {
        width: 100px;
        margin: auto;
    }
    

    Or set the text-align to center...

    td {
        text-align: center;
    }
    
    0 讨论(0)
  • 2021-01-30 19:47
    td image 
    {
        display: block;
        margin-left: auto;
        margin-right: auto;
    }
    
    0 讨论(0)
  • 2021-01-30 19:50

    As per my analysis and search on the internet also, I could not found a way to centre the image vertically centred using <div> it was possible only using <table> because table provides the following property:

    valign="middle"
    
    0 讨论(0)
提交回复
热议问题