CSS 盒子水平排布的三种方式

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>盒子水平排布的三种方式</title>
	<style>
		.contain {
			width: 900px;
			height: 600px;
			margin: 100px auto;
		}
		.block {
			width: 100%;
			height: 33.33%;
			font-size: 50px;
			line-height: 200px;
			text-align: center;
			border: 1px solid #ddd
		}

		/* 方法一 flex 方法 */
		.block:first-child{
			display: flex;
		}
		.inA:nth-child(1){
			height: 100%;
			flex: 1
		}
		.inA:nth-child(2){
			height: 100%;
			flex: 1
		}
		.inA:nth-child(3){
			height: 100%;
			flex: 1
		}
		.block:nth-child(2){
			position: relative;
		}

		/* 方法二 绝对定位方法 */
		.inB{
			position: absolute;
			height: 100%;
			width: 33.333%
		}
		.inB:nth-child(1) {
			left: 0;
		}
		.inB:nth-child(2) {
			left: 33.33%;
		}
		.inB:nth-child(3) {
			right: 0;
		}

		/* 方法三 浮动方法 */
		.inC{
			float: left;
			width: 33.33%;
		}

		/* 颜色 */
		.bacRed {
			background: red;
		}
		.bacsky {
			background: skyblue;
		}
		.bacyellow {
			background: yellow
		}
	</style>
</head>
<body>
	<div class="contain">
		<div class="block">
			<div class="inA bacRed"></div>
			<div class="inA bacsky"></div>
			<div class="inA bacyellow"></div>
		</div>
		<div class="block">
			<div class="inB bacsky"></div>
			<div class="inB bacyellow"></div>
			<div class="inB bacRed"></div>
		</div>
		<div class="block">
			<div class="inC bacyellow"></div>
			<div class="inC bacRed"></div>
			<div class="inC bacsky"></div>
		</div>
	</div>
</body>
</html>

在这里插入图片描述

  • 8
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值