弹性盒子布局(2)

一、项目单独布局在单独的项目上面单独设置属性

1、align-self:(基于交叉轴进行布局)

align-self:auto默认值,
align-self:start单独上对齐
align-self:end单独下对齐
align-self:center单独中间对齐

2、弹性布局中每个项目单独有个order数值,默认为0,数值越小,项目越靠前

实例:

<style>
	     .box{
		width: 500px;
		height: 500px;
		background-color: black;
		display: flex;
		align-items:center;
		}
			.box .one,
			.box .two,
			.box .three
			{
				width: 100px;
				height: 100px;
			}
			.one{
				background-color: #0000FF;
			}
			.two{
				background-color: green;
				/* 单独对这个块进行定义, */
				align-self:start;
				order:-1;
			}
			.three{
				background-color: red;
			}
		</style>
	</head>
	<body>
		<div class="box">
			<div class="one">项目1</div>
			<div class="two">项目2</div>
			<div class="three"> 项目3</div>
		</div>
	</body>

运行截图:

 3、项目放大

flex-grow:0 项目默认为不放大

实例:fle-grow:1和flex-grow:2  将剩余的200px分为了三份,分别赋予给了two和three。

<style>
		.box {
			width: 500px;
			height: 500px;
			background-color: black;
			display: flex;
			align-items: center;
		}

		.box .one,
		.box .two,
		.box .three {
			width: 100px;
			height: 100px;
		}

		.one {
			background-color: #0000FF;
		}

		.two {
			background-color: green;
			/* 将剩下的200px空间分给two,
					数值为1,two和three总共将剩余的分了三分,two占一份
				 */
			flex-grow: 1;
		}

		.three {
			background-color: red;
			/* 
				数值为2,three占2份
				 */
			flex-grow: 2;
		}
	</style>
</head>

<body>
	<div class="box">
		<div class="one">项目1</div>
		<div class="two">项目2</div>
		<div class="three"> 项目3</div>
	</div>

4.项目缩小

flex-shrink:1默认为1,缩小一份

与项目扩大同理。

<style>
		.box {
			width: 500px;
			height: 500px;
			background-color: black;
			display: flex;
			align-items: center;
		}

		.box .one,
		.box .two,
		.box .three {
			width: 300px;
			height: 300px;
		}

		.one {
			background-color: #0000FF;
			/* 将多出的400px空间分给one、two、three */
			/* one默认缩小一份 */
		}

		.two {
			background-color: green;
			/* 
					数值为2,two缩小两份
				 */
			flex-shrink: 2;
		}

		.three {
			background-color: red;
			/* 
				数值为2,three缩小占2份
				 */
			flex-shrink: 2;
		}
	</style>
</head>

<body>
	<div class="box">
		<div class="one">项目1</div>
		<div class="two">项目2</div>
		<div class="three"> 项目3</div>
	</div>

运行截图:

 5、简写

flex:auto    、    flex:1 1 auto

        父容器有剩余时,等比例放大,空间不足时,等比例缩小

flex:none  flex:0 0 auto  

        默认值,没有变化

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

棋宣

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值