Position DIV relative to another DIV?

前端 未结 4 2142
既然无缘
既然无缘 2020-12-08 04:39

Is it possible to position a DIV relative to another DIV? I imagine this can be done by first placing it inside of the reference DIV, and then using position: relative

4条回答
  •  情歌与酒
    2020-12-08 04:53

    You need to set postion:relative of outer DIV and position:absolute of inner div.
    Try this. Here is the Demo

    #one
    {
        background-color: #EEE;
        margin: 62px 258px;
        padding: 5px;
        width: 200px;
        position: relative;   
    }
    
    #two
    {
        background-color: #F00;
        display: inline-block;
        height: 30px;
        position: absolute;
        width: 100px;
        top:10px;
    }​
    

提交回复
热议问题