How to center a “position: absolute” element

后端 未结 26 3262
-上瘾入骨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 05:52

    You can try this way :

    * { margin: 0px; padding: 0px; }
    #body { height: 100vh; width: 100vw; position: relative; 
            text-align: center; 
            background-image: url('https://s-media-cache-ak0.pinimg.com/originals/96/2d/ff/962dff2247ad680c542622e20f44a645.jpg'); 
             background-size: cover; background-repeat: no-repeat; }
    .text { position: absolute; top: 0; bottom: 0; left: 0; right: 0; height:100px; 
            display: inline-block; margin: auto; z-index: 999999; }
    
    
    	

    Random

提交回复
热议问题