How to center a “position: absolute” element

后端 未结 26 3329
-上瘾入骨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:57

    to center a a position:absolute attribute you need to set left:50% and margin-left: -50% of the width of the div.

    
    
    
    
    
     
    should be centered horizontaly

    for vertical center absolute you need to do the same thing bud not with left just with top. ( NOTE: html and body must have min-height 100%; )

    
    
    
    
     
    should be centered verticaly

    and can be combined for both

       
     
    
    
    
     
    should be centered

提交回复
热议问题