Vertical align image inside an anchor with CSS

后端 未结 1 844
無奈伤痛
無奈伤痛 2021-02-18 17:09

I would like to vertical align an image inside an anchor element like this:

1条回答
  •  日久生厌
    2021-02-18 17:40

    Try this:

    .thumbnail {
        line-height: 150px; // height taken from OPs plunker
    }
    .thumbnail img {
       margin: auto;
       vertical-align: middle; 
       display: inline-block;
    } 
    

    Add display: inline-block; and set the line-height to the parent anchor element to middle align images vertically.

    LIVE EXAMPLE

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