12.5学习笔记

定位

定位分为固定定位(fixed)、相对定位(relative)、绝对定位(absolute)、静态定位(static)

/*相对定位relative:相对于它本身应该在的位置定位,如果所有父元素都没有,那么最后就找到body定位*/
#d2{
    width: 100px;
    height: 100px;
    background: red;
    position: relative;
    bottom: 10px;
    right: 10px;  
}

/*绝对定位absoulte:相对于有postion属性的父元素定位*/
#d22{
    width: 100px;
    height: 100px;
    background: grey;
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 101;/*谁的值大谁在上面 前提是两个元素必须有postion属性*/

}

固定定位fixed:相对于用户看到的屏幕定位

 

posted @ 2020-12-07 15:24  辛宗  阅读(48)  评论(0)    收藏  举报