day06

1定位

  • 相对定位relation
  • 绝对定位absolute
div{
            width: 100px;
            height: 100px;
            background: red;
            position: relative;
            left:200px;
            top:200px;
            /*相对定位一般不使用right,bottom*/
            /*right:0px;*/
            /*bottom:10px;*/
        }
  • 相对定位就是元素在页面上的正常位置

2绝对定位

  • 绝对定位的元素移动的位置,是离他最近的给了定位的父元素left,right,top,bottom
.parent{
            width: 200px;
            height: 200px;
            background-color: red;
            position: relative;
        }
            .child{
            left,right,top,bottom*/
            width: 50px;
            height: 50px;
            background: green;
            position: absolute;
            right: 0;
            bottom: 0;
}

3固定定位

  • fixed固定定位
 div{
            width: 20px;
            height: 50px;
            background: red;
            position: fixed;
            right: 10px;
            bottom: 130px;
        }
- 例如 “↑顶部”  “二维码”

4堆叠顺序

  • z-index设置给了absolute定位元素的堆叠顺序 谁大谁就在上面
.parent{
            width: 300px;
            height: 300px;
            background: red;
            position: relative;
        }
        .one{
            width: 100px;
            height: 100px;
            background:green;
            position:absolute;
            z-index: 100;
        }
        .two{
            width: 200px;
            height: 50px;
            background: blue;
            position: absolute;
            z-index: 101;
        }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 14,683评论 1 92
  • 1.相对定位 相对定位一般不使用right,bottom 2.绝对定位 绝对定位的元素移动的位置,是离它最近的给了...
    ZhouhaoJS阅读 2,087评论 0 2
  • 今天学到了什么? 一、定位 1.相对定位(父元素) 2.绝对定位(子元素) 3.固定定位 固定定位效果图 二、元素...
    yt1997阅读 2,675评论 0 3
  • 今天学到了什么 1.定位 1.1相对定位 相对定位就是元素在页面上正常的位置 2.2 绝对定位 绝对定位的元素移动...
    努力进化阅读 1,579评论 0 0
  • 今天是2018年7月16日 1.相对定位 给元素设置position: relative;可以使元素处于相对定位中...
    鱼翅大魔王阅读 1,404评论 0 0