need help CSS centering with absolute positioning

后端 未结 9 1470
庸人自扰
庸人自扰 2021-02-14 07:41

I\'ve never been totally satisfied with my various solutions to centering content in a web page. the

tag has been deprecated back in the middle of th
9条回答
  •  轮回少年
    2021-02-14 08:04

    The easiest way:

    #element {
    
    position: absolute; /*Absolute Position*/
    
    top: 0; 
    left: 0;          /*Set the 4 coordinates to zero*/
    bottom: 0; 
    right: 0;
    
    margin: auto;      /*Margin to Auto*/
    
    height: 150px;   /*Set the Height and Width*/
    width:150px;
    
    background:green; /* Backgroung:optional*/
    

    }

    This will bring it right at the middle, no matter it's size.

    Hope that helps!

    See Fiddle: http://jsfiddle.net/kfPC6/

提交回复
热议问题