Center an Image vertically and horizontally using CSS

前端 未结 10 1059
遥遥无期
遥遥无期 2020-11-30 08:12

How do I vertically and horizontally center an image when I do not know the size of it? I asked this question and someone suggested using a table. This isn\'t the first time

10条回答
  •  旧巷少年郎
    2020-11-30 08:33

    If you don't mind losing the img-tag, you can use background-image to center an image in a container block.

    markup:

    style:

    .imagebox
    {
      width: 500px;
      height: 500px;
      border: solid 1px black;
      background-repeat: no-repeat;
      background-position: 50% 50%;
    }
    

提交回复
热议问题