How to center an img inside a div

后端 未结 4 1513
予麋鹿
予麋鹿 2021-01-24 18:00

I\'m trying something that should be pretty easy but i can\'t figure out how to make it.

I have html source like this:

&l
4条回答
  •  灰色年华
    2021-01-24 18:06

    If the image dimensions are static then something like this would work for you

    .product img {
       position: absolute;
       top: 50%;
       left: 50%;
       width: 300px;
       height: 300px;
       margin-top: -150px; /* Half the height */
       margin-left: -150px; /* Half the width */
    }
    

提交回复
热议问题