伸缩布局

一、伸缩布局

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>伸缩布局</title>
	<style type="text/css">
		
		* {
			padding: 0;
			margin: 0;
		}

		section {
			height: 300px;
			width: 80%;
			/* background-color: pink; */
			margin: 100px auto;
			/* 父亲添加伸缩布局 */
			display: flex; /* section部分使用伸缩布局 */
		}

		section div {
			height: 100%;
			flex: 1; /* 伸缩布局中每一个子元素所占的份数 */
		}
	
		section div:nth-child(1) {
			background-color: pink;
			flex: 2;
		}

		section div:nth-child(2) {
			background-color: blue;
		}
		
		section div:nth-child(3) {
			background-color: yellow;
			flex: 3;
		}


	</style>
</head>
<body>
	<section>
		<div></div>
		<div></div>
		<div></div>
	</section>
</body>
</html>

二、伸缩布局之固定宽度

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>伸缩布局固定宽度</title>
	<style type="text/css">

		* {
			padding: 0;
			margin: 0;
		}
		
		section {
			width: 100%;
			height: 300px;
			display: flex; /* 使用伸缩布局 */
		}

		section:div {
			flex: 1;
		}

		section div:nth-child(1){
			width: 200px; /* 指定固定宽度 */
			background-color: pink;
		}

		section div:nth-child(2){
			flex: 2;
			background-color: purple;
			margin: 0 10px;
		}

		section div:nth-child(3){
			flex: 3;
			background-color: blue;
		}


	</style>
</head>
<body>
	<section>
		<div>1</div>
		<div>2</div>
		<div>3</div>
	</section>
</body>
</html>

三、伸缩布局之水平分布

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>伸缩布局水平分布</title>
	<style type="text/css">

		* {
			padding: 0;
			margin: 0;
		}
		
		section {
			width: 80%;
			height: 300px;
			margin: 100px auto;
			
			display: flex; /* 使用伸缩布局 */
			min-width: 200px; /* 限定最小宽度 */
			flex-direction: column; /* 设定分布方向 */
		}

		section:div {
			flex: 1;
		}

		section div:nth-child(1){
			background-color: pink;
		}

		section div:nth-child(2){
			background-color: purple;
		}

		section div:nth-child(3){
			background-color: blue;
		}


	</style>
</head>
<body>
	<section>
		<div>1</div>
		<div>2</div>
		<div>3</div>
	</section>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值