day06

1.相对定位

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

相对定位一般不使用right,bottom

2.绝对定位

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

绝对定位的元素移动的位置,是离它最近的给了定位的父元素

3.元素水平垂直居中

 .parent{
            position: relative;
            width:300px;
            height:300px;
            background:red;
        }
        .child{
            position:absolute;
            width:50px;
            height:50px;
            background:green;
            left:50%;
            top:50%;
            margin-left:-25px;
            margin-top: -25px;
        }

4.banner

 html,body{
            width:100%;
            height:100%;
        }
        /* 子元素left,top值给百分比,是相对于父元素的width,height而言的 */
        img{
            position:absolute;
            left:50%;
            top:50%;
            width:618px;
            height:128px;
            margin-left:-307px;
            margin-top: -64px;
        }
        body{
            position: relative;
            background:url("images/bg.png") no-repeat center center;
            background-size: cover;

子元素left,top值给百分比,是相对于父元素的width,height而言的

5.search

.search{
            margin:100px;width:240px;
            height:40px;position: relative;
        }
        button{
            position:absolute;top:50%;margin-top: -11px;

            right:5px;width:23px;height:22px;
            background: url("images/icon4.png");border:none;
        }
        input{
            padding-left:20px;border:none;
            border-radius: 30px;outline: none;
            width:220px;height:40px;background:#eee;
        }

6.百度一下

 .search{
            margin-left: auto;
            margin-right: auto;
            margin-top: 50px;
            width:640px;
            height:38px;
            position: relative;
        }
        input{
            border:1px solid #b8b8b8;
            width:540px;
            height:36px;
            position:absolute;
            left:0;
            top:0;
        }
        button{
            color:#fff;
            border:1px solid #3385ff;
            background:#3385ff;
            width:100px;
            height:38px;
            position:absolute;
            right:0;

        }

7.fixed

 div{
            width:20px;
            height:50px;
            background:red;
            position:fixed;
            right:10px;
            bottom:130px;
        }

8.z-index

 /* 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;position:absolute;
            background:blue;
            z-index: 101;
        }
        .parent:hover .one{
            z-index: 200;
        }

z-index设置给了absolute定位元素的堆叠顺序

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 13,842评论 1 92
  • CSS 定位 CSS有三种基本的定位机制:普通流,浮动,绝对定位(absolute, fixed):普通流是默认定...
    _空空阅读 5,865评论 0 15
  • CSS 是什么 css(Cascading Style Sheets),层叠样式表,选择器{属性:值;属性:值}h...
    崔敏嫣阅读 1,515评论 0 5
  • 知识要点梳理 1.相对定位 2.绝对定位 3.元素垂直水平居中 4.搜索框 百度搜索框 5.fixed 6.z-i...
    向阳_095c阅读 167评论 0 0
  • 七绝·懒觉 晓窗罗帐清秋梦,几案铃钟唤取轻。 翻枕欹眠还掩耳,犹闻邻舍读书声。 七绝·懒煮 邻家炊饭起疏烟,掬水轻...
    泓颖阅读 981评论 6 12