Why is this absolutely positioned element not positioning relative to its container?

前端 未结 2 1585
故里飘歌
故里飘歌 2021-01-27 05:40

I have this simple code to place two div #container elements side by side. In each of these there is a child div #child which I would like to position

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-27 06:01

    To position the child relative to its parent, just add position:relative to the PARENT'S style - then all children with position:absolute will be absolute relative to the parent.

    .container {
        float:left;
        margin-right: 10px;
        position:relative;
    }
    

提交回复
热议问题