Centering an image that is in an anchor tag

前端 未结 5 1821
迷失自我
迷失自我 2021-01-23 17:50

I have an image in an anchor tag, and I need to center it.

I have managed to do so using this technique that I just came across messing about in the DOM inspector: http:

5条回答
  •  一整个雨季
    2021-01-23 18:30

    Demo Fiddle

    Try:

    #container{
        width: 600px;
        height:600px;
        background: red;
        display: table-cell; /* <-- allows use of vertical align */
        text-align:center; /* <-- horizontal centering */
        vertical-align:middle; /* <-- vertical centering */
    }
    

    Use the above and you wont need any more CSS for the img

提交回复
热议问题