How to center a “position: absolute” element

后端 未结 26 3328
-上瘾入骨i
-上瘾入骨i 2020-11-21 05:35

I\'m having a problem centering an element that has the attribute position set to absolute. Does anyone know why the images are not centered?

<
26条回答
  •  既然无缘
    2020-11-21 06:16

    The simpler, the best:

    img {
                top: 0;
                bottom: 0;
                left: 0;
                right: 0;
                margin: auto auto;
                position: absolute;
    }
    

    Then you need to insert your img tag into a tag that sports position:relative property, as follows:

提交回复
热议问题