• 浮动原理


    浮动原理:
    w3c:
    float 属性定义元素在哪个方向浮动。以往这个属性总应用于图像,使文本围绕在图像周围,不过在 CSS 中,任何元素都可以浮动。浮动元素会生成一个块级框,而不论它本身是何种元素。
    浮动非替换元素要指定一个明确的宽度;否则,它们会尽可能地窄。
    注释:假如在一行之上只有极少的空间可供浮动元素,那么这个元素会跳至下一行,这个过程会持续到某一行拥有足够的空间为止。
    我:
    (以下以全部设置为float:left;为例)
    如果包含框太窄,无法容纳水平排列的几个浮动元素,那么第一个容纳不下的浮动块会带着它后面 的浮动块一起向下移动,直到可以向左移动,则向左移动到边框或另一个浮动框,然后判断是否能容纳第一个浮动块,能则第一个浮动块留在这里,其后面的浮动块继续前面的操作,不能则第一个浮动块和后面的浮动块继续前面的操作。
    下面是几个例子:
    html
    <!DOCTYPE html>
    <html>
    <head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="test01.css"/>
    </head>
    <body>
    <div class="div_outer">
    <div class="div_in1">
    11111111111111111111
    </div>
    <div class="div_in2">
    22222222222222222222
    </div>
    <div class="div_in3">
    33333333333333333333
    </div>
    <div class="div_in4">4444</div>
    <div class="div_in5">4444</div>
    <div class="div_in6">4444</div>
    </div>
    </body>
    </html>

    css
    .div_outer{
    height: 500px;
    280px;
    background: #000;
    }

    /* 例1 */
    /*.div_in1{*/
    /*height: 100px;*/
    /* 100px;*/
    /*background: red;*/
    /*float: left;*/
    /*}*/
    /*.div_in2{*/
    /*height: 50px;*/
    /*150px;*/
    /*background: green;*/
    /*float: left;*/
    /*}*/
    /*.div_in3{*/
    /*height: 60px;*/
    /* 50px;*/
    /*background: blue;*/
    /*float: left;*/
    /*}*/
    /*.div_in4{*/
    /*height: 100px;*/
    /* 140px;*/
    /*background: orange;*/
    /*float: left;*/


    /* 例2 */
    /*.div_in1{*/
    /*height: 100px;*/
    /* 100px;*/
    /*background: red;*/
    /*float: left;*/
    /*}*/
    /*.div_in2{*/
    /*height: 50px;*/
    /*150px;*/
    /*background: green;*/
    /*float: left;*/
    /*}*/
    /*.div_in3{*/
    /*height: 60px;*/
    /* 50px;*/
    /*background: blue;*/
    /*float: left;*/
    /*}*/
    /*.div_in4{*/
    /*height: 30px;*/
    /* 30px;*/
    /*background: orange;*/
    /*float: left;*/
    /*}*/

    /* 例3 */
    .div_in1{
    height: 100px;
    100px;
    background: red;
    float: left;
    }
    .div_in2{
    height: 50px;
    150px;
    background: green;
    float: left;
    }
    .div_in3{
    height: 60px;
    50px;
    background: blue;
    float: left;
    }
    .div_in4{
    height: 100px;
    140px;
    background: orange;
    float: left;
    }
    .div_in5{
    height: 90px;
    100px;
    background: grey;
    float: left;
    }
    .div_in6{
    height: 50px;
    50px;
    background: orchid;
    float: left;
    }

     

  • 相关阅读:
    AngularJs跨域请求Java的实现---博客园老牛大讲堂
    JavaWeb的json包装以及跨域问题--博客园老牛大讲堂
    无网络联机打单机游戏---博客园老牛大讲堂
    H5移动开发AUI框架入门---博客园老牛大讲堂
    MySql链表语句--博客园老牛大讲堂
    Jquery的基本用法--博客园老牛大讲堂
    Java的日期字符串的转换---博客园老牛大讲堂
    实现访问电脑百度,访问到自己的工程方法---博客园老牛大讲堂
    Jquery的闭包理解--匿名函数--博客园老牛大讲堂
    xampp的安装和配置与HBuilder的配置--博客园老牛大讲堂
  • 原文地址:https://www.cnblogs.com/dxwen/p/10776445.html
Copyright © 2020-2023  润新知