need help CSS centering with absolute positioning

后端 未结 9 1249
庸人自扰
庸人自扰 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:12

    Use relative positioning on the parent and give that same element the property:

    margin: 0 auto;
    

    The parent is now positioned and you should be able to set elements absolutely within it.

    Example:

    div#page{
      position:relative;
      width:400px;
      margin:0 auto;
    }
    
    div#page #absoluteExample{
      position:absolute;
      top:18px;
      left:100px;
    }
    

提交回复
热议问题