美文网首页
高度塌陷、定位

高度塌陷、定位

作者: 2simple | 来源:发表于2018-07-11 17:15 被阅读0次

    高度塌陷
    块的格式化环境 BFC BFC (隐含的属性)

    1.父元素的垂直外边距不会和子元素重叠;

    2.开启BFC的元素不会被浮动元素所覆盖;

    3.开启BFC的元素可以包含浮动的子元素;

    如何开启BFC

    1.设置元素浮动;

    2.设置元素绝对路径;

    3.设置元素为inline-block ;

    4.将元素的 overflow 设置为一个非visible的值;

    overflow : hidden

    IE6 以及以下的设置不能设置BFC,

    zoom表示放大的意思,zoom : 1;

    去掉项目符号: list-style : none;

    去掉超链接的下划线 : text-decoration : none;

    clear 清除浮动

    内联元素转换为块元素 display : block;

    left:忽略左侧浮动

    right:忽略右侧浮动

    both:忽略全部浮动略浮动,默认值

    position 定位

    可以使用position属性把一个元素放置到网页中的任何位置。

    static relative absolute fixed

    相对定位

                 每个元素在页面的文档流中都有一个自然位置。相
    
                 对于这个位置对元素进行移动就称为相对定位。周 围的元素完全不受此影响。
    
                 当将position属性设置为relative时,则开启了元素的相对定位。
    
                 当开启了相对定位以后,可以使用top、right、 bottom、left四个属性对元素进行定位
    

    特点 : 使文本流。元素在文本流中的位置不会改变。

            相对定位不会改变元素原来的特性。
    
            相对定位会使元素的层级提升,使元素可以覆盖文本流中的元素。
    

    绝对定位

                绝对定位指使元素相对于html元素或离他最近的祖先定位元素进行定位。
    
                当将position属性设置为absolute时,则开启了元素的绝对定位。
    
                当开启了绝对定位以后,可以使用top、right、 bottom、left四个属性对元素进行定位。
    

    特点 : 使素完全脱离文本流。

                  绝对定位的块元素的宽度会被其内容撑开。
    
                  绝对定位会使行内元素变成块元素。
    
                  一般使用绝对定位时会同时为其父元素指定一个相对定位,以确保元素可以相对于父元素进 行定位。
    

    固定定位

                固定定位的元素会被锁定在屏幕的某个位置上,当访问者滚动网页时,固定元素会在屏幕上保持不动。
    
                当将position属性设置为fixed时,则开启了元素的 固定定位。
    
                当开启了固定定位以后,可以使用top、right、bottom、left四个属性对元素进行定位。
    
                固定定位的其他特性和绝对定位类似。
    

    特点 : 当元素开启定位以后就可以设置z-index这个属性。

               这个属性可以提升定位元素所在的层级。
    
               z-index可以指定一个整数作为参数,值越大元素显示的优先级越高,也就是z-index 值较大的元素会显示在网页的最上层。
    

    作业:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>作业</title>
        <style>
            *{
                margin: 0;
                padding: 0;
            }
            .quan{
                width:300px;
                margin: 50px auto;
    
            }
            .t1{
                border-top: 2px #019e8b solid;
                height: 36px;
                background-color: #f5f5f5;
                line-height:36px;
                padding: 0 22px 0 16px;
            }
            .t1 a{
                font-size: 12px;
                float: right;
                color: red;
            }
            .t1 h3{
                font: 16px/36px '微软雅黑';
    
            }
            .content{
                border: 1px solid #deddd9;
                padding: 0 28px 0 20px;
            }
            .content a{
                color: black;
                text-decoration: none;
                font-size: 12px;
            }
            .content a:hover{
                color: blue;
                text-decoration: underline;
            }
            .content ul{
                list-style: none;
                border-bottom: 1px dashed #deddd9;
            }
            .content .teat{
                color: red;
                font-weight: bold;
            }
            .content .right{
                float: right;
    
            }
            .content .h3{
                margin-top: 15px;
                margin-bottom: 15px;
            }
            .content li{
                margin-bottom: 15px;
            }
            .content .no-border{
                border: none;
    
            }
        </style>
    </head>
    <body>
        <div class="quan">
            <div class="t1">
                <a href="#">18年面授开班计划</a>
                <h3>近期开班</h3>
            </div>
            <div class="content">
                <h3><a href="#">人工智能+Python-高薪就业班</a></h3>
                <ul>
                    <li>
                        <a href="#">开班时间:<span class="teat">2018-04-26<span></a>
                        <a href="#" class="right"><span class="teat">预约报名<span></a>
                    </li>
                    <li>
                        <a href="#">开班时间:<span class="teat">2018-03-23<span></a>
                        <a href="#" class="right"><span  class="teat">无座,名额爆满<span></a>
                    </li>
                    <li>
                        <a href="#">开班时间:<span >2018-01-23<span></a>
                        <a href="#" class="right"><span >开班盛况<span></a>
                    </li><li>
                        <a href="#">开班时间:<span >2017-12-20<span></a>
                        <a href="#" class="right"><span >开班盛况<span></a>
                    </li><li>
                        <a href="#">开班时间:<span >2017-11-18<span></a>
                        <a href="#" class="right"><span >开班盛况<span></a>
                    </li>
                </ul>
                <h3><a href="#">Android开发+测试-高薪就业班</a></h3>
                <ul>
                    <li>
                        <a href="#">开班时间:<span class="teat">2018-04-26<span></a>
                        <a href="#" class="right"><span class="teat">预约报名<span></a>
                    </li>
                    
                    <li>
                        <a href="#">开班时间:<span >2018-03-23<span></a>
                        <a href="#" class="right"><span >开班盛况<span></a>
                    </li><li>
                        <a href="#">开班时间:<span >2018-01-23<span></a>
                        <a href="#" class="right"><span >开班盛况<span></a>
                    </li><li>
                        <a href="#">开班时间:<span >2017-12-20<span></a>
                        <a href="#" class="right"><span >开班盛况<span></a>
                    </li>
                </ul>
                <h3><a href="#">大数据软件开发-青芒工作室</a></h3>
                <ul class="no-border">
                    <li>
                        <a href="#">开班时间:<span class="teat">2018-04-26<span></a>
                        <a href="#" class="right"><span class="teat">预约报名<span></a>
                    </li>
                    
                    <li>
                        <a href="#">开班时间:<span >2018-01-23<span></a>
                        <a href="#" class="right"><span >开班盛况<span></a>
                    </li>
    
                </ul>
    
            </div>
        </div>
    </body>
    </html>
    
    11875274-920f91fffcb7ad79.png

    相关文章

      网友评论

          本文标题:高度塌陷、定位

          本文链接:https://www.haomeiwen.com/subject/kdzhpftx.html