1. 程式人生 > >CSS學習——初識浮動(float)

CSS學習——初識浮動(float)

浮動(float)

浮動的作用是讓兩個div左右佈局,在同一行顯示。

程式碼例項

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			.box{
				height: 100px;
				margin-bottom: 10px;
				background-color: green;
				width: 50%;
				float: left;
			}
			.box2{
				height: 100px;
				margin-bottom: 10px;
				background-color: orange;
				width: 50%;
				float: right;
			}
		</style>
	</head>
	<body>
		<!--需求:兩個盒子(div)左右佈局-->
		<div class="box"></div>
		<div class="box2"></div>
	</body>
</html>