南宁企业oa系统开发,挑战百日学习计划第48天(float清除浮动方法)

南宁oa系统开发定制:http://www.nasiot.com

南宁企业oa系统开发定制
如图所示,当元素浮动的情况之下, 父级元素就会高度坍塌,解决的方法有两种主流模式,我这里做简单的介绍
1.使用clear:both 清楚浮动: 即在浮动元素的末端清除元素浮动

<html>
	<head>
		<meta charset="utf-8">
		<title>Span元素</title>
		<style>
			img{
				max-width: 100px;
			}
			.box{				
				border:1px solid #f55;	
			    
			}
			ul{
				list-style: none;
			}
			li{float:left;}
						
			.clear{
				clear:both;
			}
		</style>
	</head>
	<body>
		<div class="box ">
		<ul>
		<li><img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1029847769,1364060861&fm=26&gp=0.jpg"></li>
		<li><img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1029847769,1364060861&fm=26&gp=0.jpg"></li>
		<div class="clear"></div>
		</ul>
	</body>
</html>

广西oa系统开发定制
重点来了
为了代码的美观,所以一般的办法就是使用:伪类after在元素的尾部追加一个空的内容,并用于清除浮动

.clearclass:after{
  display:block;
  content:"";
  clear:both;
}

然后把这个类加入在父元素之中即可,这样子就解决坍塌问题,
代码如下

<html>
	<head>
		<meta charset="utf-8">
		<title>Span元素</title>
		<style>
			img{
				max-width: 100px;
			}
			.box{				
				border:1px solid #f55;	
			    
			}
			ul{
				list-style: none;
			}
			li{float:left;}
						
			.clearclass::after{
				content: "";
				display: block;
				clear:both;				
			}
		</style>
	</head>
	<body>
		<div class="box clearclass">
		<ul>
		<li><img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1029847769,1364060861&fm=26&gp=0.jpg"></li>
		<li ><img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1029847769,1364060861&fm=26&gp=0.jpg"></li>
		
		</ul>
	</body>
</html>

方法2:父级元素,使用overflow:hidden;即可解决问题 bfc什么的,浮动元素也计算高度

.box{				
				border:1px solid #f55;	
			    overflow:hidden;
			}

好了,教程就到这里,大家一起学习加油!

广西企业oa系统开发定制:www.nasiot.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值