Vertical align all(!) elements in TD?

前端 未结 11 1067
鱼传尺愫
鱼传尺愫 2021-01-31 14:28

I have a simple table with 1 TD with vertical-align:middle;. This TD contains an Image :



        
11条回答
  •  迷失自我
    2021-01-31 15:02

    This CSS attribute doesn't go on any other kinds of elements. When the novice developer applies vertical-align to normal block elements (like a standard ) most browsers set the value to inherit to all inline children of that element.

    You simply need to add vertical-align: middle to the class.

    Your CSS should look like this...

    table
    {
      border:solid 1px red;
      width:300px;
    }
    
    td
    {
      height:100px;
      vertical-align:middle;
      width:100%;
      border:solid 1px green;
    }
    img
    {
      height:43px;width:43px;
      vertical-align: middle;
    }
    

    You can view the Sample Fiddle...

提交回复
热议问题