• 清除浮动


    参考学习:https://www.cnblogs.com/nxl0908/p/7245460.html

    1.父级div定义伪类:after和zoom
    2.在结尾处添加空div标签clear:both /(结尾处加br标签clear:both)
    3.父级div定义display:table
    4.父级div定义height
    5.父级div定义overflow:hidden
    6.父级div定义overflow:auto
    7.父级div也一起浮动

    1.父级div定义伪类:after和zoom

    	<style>
    		.box1{
    			 100px;
    			height: 100px;
    			background-color: red;
    			float: left;
    		}
    		.box2{
    			 100px;
    			height: 100px;
    			background-color: blue;
    			float: left;
    		}
    		.container{
    			border:1px solid black;
    		}
    		.box3{
    			height: 200px;
    			background-color: green;
    		}
    		
    		 **.clearfloat:after{
    		 	display:block;
    		 	clear:both;
    		 	content:"";
    		 	visibility:hidden;
    		 	height:0}
            .clearfloat{zoom:1}**
    	</style>
    
    <body>
    	<div class="container clearfloat" >
    		<div class="box1"></div>
    		<div class="box2"></div>
    	</div>
    	<div class="box3">	
    	</div>
    </body>
    

    2.在结尾处添加空div标签clear:both

    	<style>
    		.box1{
    			 100px;
    			height: 100px;
    			background-color: red;
    			float: left;
    		}
    		.box2{
    			 100px;
    			height: 100px;
    			background-color: blue;
    			float: left;
    		}
    		.container{
    			border:1px solid black;
    		}
    		.box3{
    			height: 200px;
    			background-color: green;
    		}
    		**.clearboth{
    			clear:both;
    		}**
    	</style>
    
    <body>
    	<div class="container">
    		<div class="box1"></div>
    		<div class="box2"></div>
    		**<div class="clearboth"></div>**
    	</div>
    	<div class="box3">
    	</div>
    </body>
    

    3.父级div定义height

    	<style>
    		.box1{
    			 100px;
    			height: 100px;
    			background-color: red;
    			float: left;
    		}
    		.box2{
    			 100px;
    			height: 100px;
    			background-color: blue;
    			float: left;
    		}
    		.container{
    			border:1px solid black;
    			**height: 100px;**
    		}
    		.box3{
    			height: 200px;
    			background-color: green;
    		}
    	</style>
    
    <body>
    	<div class="container" >
    		<div class="box1"></div>
    		<div class="box2"></div>
    	</div>
    	<div class="box3">
    	</div>
    </body>
    

    4.父级div定义overflow:hidden

    	<style>
    		.box1{
    			 100px;
    			height: 100px;
    			background-color: red;
    			float: left;
    		}
    		.box2{
    			 100px;
    			height: 100px;
    			background-color: blue;
    			float: left;
    		}
    		.container{
    			border:1px solid black;
    			**overflow: hidden;**
    		}
    		.box3{
    			height: 200px;
    			background-color: green;
    		}
    	</style>
    
    <body>
    	<div class="container" >
    		<div class="box1"></div>
    		<div class="box2"></div>
    	</div>
    	<div class="box3">	
    	</div>
    </body>
    

    5.父级div定义overflow:auto

    	<style>
    		.box1{
    			 100px;
    			height: 100px;
    			background-color: red;
    			float: left;
    		}
    		.box2{
    			 100px;
    			height: 100px;
    			background-color: blue;
    			float: left;
    		}
    		.container{
    			border:1px solid black;
    			overflow: auto;
    		}
    		.box3{
    			height: 200px;
    			background-color: green;
    		}
    	</style>
    
    <body>
    	<div class="container" >
    		<div class="box1"></div>
    		<div class="box2"></div>
    	</div>
    	<div class="box3">
    	</div>
    </body>
    

    6.父级div也一起浮动

    	<style>
    		.box1{
    			 100px;
    			height: 100px;
    			background-color: red;
    			float: left;
    		}
    		.box2{
    			 100px;
    			height: 100px;
    			background-color: blue;
    			float: left;
    		}
    		.container{
    			border:1px solid black;
    			**float:left;**
    		}
    		.box3{
    			height: 200px;
    			background-color: green;
    			**clear:both;**
    		}
    	</style>
    
    <body>
    	<div class="container" >
    		<div class="box1"></div>
    		<div class="box2"></div>
    	</div>
    	<div class="box3">
    	</div>
    </body>
    

    7.父级div定义display:table

    	<style>
    		.box1{
    			 100px;
    			height: 100px;
    			background-color: red;
    			float: left;
    		}
    		.box2{
    			 100px;
    			height: 100px;
    			background-color: blue;
    			float: left;
    		}
    		.container{
    			border:1px solid black;
    			display:table;
    		
    		}
    		.box3{
    			height: 200px;
    			background-color: green;
    
    		}
    	</style>
    
    <body>
    	<div class="container" >
    		<div class="box1"></div>
    		<div class="box2"></div>
    	</div>
    	<div class="box3">
    	</div>
    </body>
    

    8、结尾处加br标签clear:both

  • 相关阅读:
    ThinkPHP整合Kindeditor多图处理示例
    KindEditor用法介绍
    MySQL 1064 错误
    Nginx中虚拟主机与指定访问路径的设置方法讲解
    AJAX PHP无刷新form表单提交的简单实现(推荐)
    教PHP程序员如何找单位(全职+实习),超有用啊!
    利用正则表达式实现手机号码中间4位用星号(*)
    PHP项目做完后想上线怎么办,告诉你免费上线方法!
    备战NOIP——模板复习16
    备战NOIP——STL复习1
  • 原文地址:https://www.cnblogs.com/princeness/p/11664958.html
Copyright © 2020-2023  润新知