How can I vertically center an image with an anchor inside a div?

前端 未结 1 2063
暗喜
暗喜 2021-01-14 21:15

I have a row of DIVs for my navigation and I\'m trying to vertically center an image with an anchor inside them using only CSS. I tried vertical-align: middle; but that isn\

1条回答
  •  -上瘾入骨i
    2021-01-14 21:46

    Don't know why you are using li to hold the anchor element. From the question there is no mention for the li. So I assume you just need one image and one anchor. Check this out:

    http://jsfiddle.net/U64Tg/2/

    Basically you just need to have the helper to have 100% height of the container div. And you need to use

    vertical-align: middle;
    display: inline-block;
    

    on all child elements in the container div to make them vertically aligned.

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