how to vertically align elements in td tag

前端 未结 4 448
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-11 14:56

I want to align 3 elements in my tag vertically in the center/middle. These are the elements that I want to align:

  1. image button (a tag)
相关标签:
4条回答
  • 2020-12-11 15:31

    Read about vertical-align in table cells here

    vertical-align:middle
    vertical-align:top
    vertical-align:bottom
    

    http://phrogz.net/css/vertical-align/

    0 讨论(0)
  • 2020-12-11 15:45

    Thanks to all for your help. I found the answer myself. This is the new code. Only the td tag has changed to add an additional attribute align=center. This will align all element within td tag in center.

    <td align="center" style="vertical-align:top;">             
        <div id="div1" style="display:inline-block; horizontal-align:center; margin-top:5px;">
         <a id="a_top" title="Top" class="ui-icon ui-icon-circle-triangle-n" style="border:0px;"></a>
        </div>
        <div id="slider_y" style="height:240px; width:6px; horizontal-align:center; margin-top:10px; "></div>
        <div id="div2" style="display:inline-block;horizontal-align:center;margin-top:10px;">
         <a id="a_bottom" title="Bottom" class="ui-icon ui-icon-circle-triangle-s" style="border:0px;"></a>
        </div>
    </td>
    
    0 讨论(0)
  • 2020-12-11 15:48

    Be careful when there are several elements in the same <TD>, the vertical alignment no longer works because the alignment is made on the different elements but together!

    For the different elements to be vertically centered, they must be separated into a new <table> with different columns!

    For example, to align an image with a <span>:

    0 讨论(0)
  • 2020-12-11 15:48
    <td style="vertical-align:top;">                
      <div id="div1" style="display:inline-block; horizontal-align:center; margin-top:5px;">
        <div align="center"><a id="a_top" title="Top" class="ui-icon ui-icon-circle-triangle-n" style="border:0px;"></a>
          </div>
      </div>
      <div id="slider_y" style="height:240px; width:6px; horizontal-align:center; margin-top:10px; "></div>
      <div id="div2" style="display:inline-block;horizontal-align:center;margin-top:10px;">
        <div align="center"><a id="a_bottom" title="Bottom" class="ui-icon ui-icon-circle-triangle-s" style="border:0px;"></a>
          </div>
      </div>
    </td>
    

    I'm not sure I completely understand, but maybe something like this?

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