Position absolute but relative to parent

前端 未结 4 1464
小鲜肉
小鲜肉 2020-11-21 05:33

I have two divs inside another div, and I want to position one child div to the top right of the parent div, and the other child div to the bottom of the parent div using cs

4条回答
  •  情话喂你
    2020-11-21 05:40

    If you don't give any position to parent then by default it takes static. If you want to understand that difference refer to this example

    Example 1::

    http://jsfiddle.net/Cr9KB/1/

       #mainall
    {
    
        background-color:red;
        height:150px;
        overflow:scroll
    }
    

    Here parent class has no position so element is placed according to body.

    Example 2::

    http://jsfiddle.net/Cr9KB/2/

    #mainall
    {
        position:relative;
        background-color:red;
        height:150px;
        overflow:scroll
    }
    

    In this example parent has relative position hence element are positioned absolute inside relative parent.

提交回复
热议问题