HTML中浮动(float)的使用2---脱标

一.浮动元素的脱标(脱离标准流)

<style type="text/css">
            .box1{width: 100px;height: 100px;background-color: aqua;
                  float: left;
            }
            .box2{width: 150px;height: 150px;background-color: brown;
                  
            }
            
            
        </style>
    </head>
    <body>
        <div class="box1"></div>
        <div class="box2"></div>
    </body>

 

因为我们将box1进行了左浮动,box1脱离了标准流,但是box2补上了box1的标准流位置

 

 

 

 

 

 

 

<style type="text/css">
            .box1{width: 100px;height: 100px;background-color: aqua;
                  float: left;
            }
            .box2{width: 150px;height: 150px;background-color: brown;
                  
            }
            
            
        </style>
    </head>
    <body>
        <div class="box1"></div>
        <div class="box2">我是文字我是文字我是文字我是文字我是文字我是文字我是文字我是文字</div>
    </body>

 

 浮动元素的字围现象,没有浮动的元素中的文字会给我们浮动元素让位置

 

二.清除浮动

clear:both;

 

posted @ 2020-03-23 14:50  陈小歪、  阅读(785)  评论(0编辑  收藏  举报