CSS布局——三个DIV横向竖向平均布局

一、正常默认布局

html代码

    <div class="div-big">
		<div class="div-small" style="background-color: lightcoral;"></div>
		<div class="div-small" style="background-color: lightgoldenrodyellow;"></div>
		<div class="div-small" style="background-color: lightskyblue;"></div>
	</div>

css代码

.div-big{
	width: 600px;
	height: 400px;
	background-color: lightseagreen;/*绿背景色*/
}
.div-big .div-small{
	width: 100px;
	height: 100px;
}

图片演示:

二、横向平均排列

html代码

    <div class="div-big">
		<div class="div-small" style="background-color: lightcoral;"></div>
		<div class="div-small" style="background-color: lightgoldenrodyellow;"></div>
		<div class="div-small" style="background-color: lightskyblue;"></div>
	</div>

css代码

.div-big{
	width: 600px;
	height: 400px;
	background-color: lightseagreen;/*绿背景色*/
	display: flex;/*重要*/
	justify-content: space-between;/*重要*/
}
.div-big .div-small{
	width: 100px;
	height: 100px;
}

图片演示

提示:

1.justify-content属性值有space-between(常用),space-around(常用),start,end,center.

三、竖向平均排列

html代码

    <div class="div-big">
		<div class="div-small" style="background-color: lightcoral;">1</div>
		<div class="div-small" style="background-color: lightgoldenrodyellow;">2</div>
		<div class="div-small" style="background-color: lightskyblue;">3</div>
	</div>

css代码

.div-big{
	width: 600px;
	height: 400px;
	background-color: lightseagreen;/*绿背景色*/
	display: flex;/*重要*/
	flex-wrap: wrap;/*重要*/    /*--让弹性盒元素在必要的时候拆行:*/
	align-content: space-between;/*重要*/
}
.div-big .div-small{
	width: 600px;/*重要*/   /*宽度一定要超过父类横向50%大小*/
	height: 100px;
}

图片演示

提示:

1.竖向平均排列是加了一行拆分属性flex-wrap: wrap;

2.子类宽度一定要注意超过父类50%的宽度,否则就会横向不拆分成竖向的。

3.justify-content属性值有space-between(常用),space-around(常用),start,end,center.

  • 13
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值