总结Margin重叠现象

本文深入探讨了HTML布局中'普通元素'与'浮动元素'之间的相互作用,具体阐述了'普通与普通大者取大'原则以及'普通对普通大者取大'、'浮动与普通无影响'和'浮动与浮动两者相加'的现象。通过实际代码示例,直观展示不同元素布局策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

普通与普通大者取大

<!DOCTYPE html>
<html>
<head>
	<title>box test</title>
	<style type="text/css">
		#box{
			width: 200px;
			height: 200px;
			background: black;
			margin-bottom: 50px;
			
		}
		#box1{
			width: 300px;
			height: 100px;
			background: blue;
			margin-top: 50px;
			
		}
	
	</style>
</head>
<body>
	<div id="box"></div>
	<div id="box1"></div>
	
</body>
</html>





float 与 float两者相加

<!DOCTYPE html>
<html>
<head>
	<title>box test</title>
	<style type="text/css">
		#box{
			width: 200px;
			height: 200px;
			background: black;
			margin-bottom: 50px;
			float: left;
		}
		#box1{
			width: 1900px;
			height: 100px;
			background: blue;
			margin-top: 50px;
			float: left;
		}
		
	</style>
</head>
<body>
	<div id="box"></div>
	<div id="box1"></div>
</body>
</html>





float对普通无影响

<!DOCTYPE html>
<html>
<head>
	<title>box test</title>
	<style type="text/css">
		#box{
			width: 200px;
			height: 200px;
			background: black;
			margin-bottom: 50px;
			float: left;
		}
		#box1{
			width: 300px;
			height: 100px;
			background: blue;
			margin-top: 50px;
			float: left;
		}
		#box2{
			background: green;
	
			height: 300px;
			width: 1800px;
			
		}
	</style>
</head>
<body>
	<div id="box"></div>
	<div id="box1"></div>
	<div id="box2"></div>
</body>
</html>





总结:普通对普通大者取大;

            float与普通无影响;

            float与float两者相加

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值