Flex布局

一.什么是flex布局?

Flex 是 Flexible Box 的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性。任何一个容器都可以指定为 Flex 布局。

话不多说直接码上代码:

1.flex-direction:row | row-reverse | column | column -reverse (决定主轴方向即排列方向)

html:

<div class="main">
	<div class="no1">1</div>
	<div class="no2">2</div>
	<div class="no3">3</div>
	<div class="no4">4</div>
	<div class="no5">5</div>
	<div class="no6">6</div>
	<div class="no7">7</div>
	<div class="no8">8</div>
	<div class="no9">9</div>
</div>

css:

.main {
	width: 100%;
	display: flex;
	flex-direction: row; /*横向排列*/
	flex-wrap: wrap; /*一排排不下自动换行*/
	text-align: center;
	line-height: 10rem;
	border: 0.126666rem solid black;
	font-size: 2rem;
}		
.main div {
	width: 10rem;
	height: 10rem;
}			
.no1 {
        background-color: blue;
}			
.no2 {
        background-color: red;
}			
.no3 {
        background-color: brown;
}			
.no4 {	
        background-color: lawngreen;
}			
.no5 {
	background-color: goldenrod;
}			
.no6 {
	background-color: aqua;
}			
.no7 {
	background-color: rosybrown;
}			
.no8 {
	background-color: cadetblue;
}			
.no9 {
	background-color: sandybrown;
}			


效果图:

flex-direction: row;

flex-direction: row-reverse;
flex-direction: column;                                 

 

 flex-direction: column-reverse;

2.justify-content:flex-end | flex-start | center | space-between | space-around (justify-content属性定义了项目在主轴上的对齐方式。)

html:

<div class="No2main">
	<div class="no40">5</div>
	<div class="no50">6</div>
	<div class="no60">7</div>
</div>

css:

.No2main {
		height: 10rem;
		display: flex;
		justify-content: flex-end;
		border: 0.126666rem solid black;
		align-items: center;
		font-size: 2rem;
		}
	 .no40 {
		width: 8rem;
		height: 8rem;
		text-align: center;
		line-height: 8rem;
		background-color: brown;
		}
	 .no50 {
		width: 8rem;
		height: 8rem;
		text-align: center;
		line-height: 8rem;
		background-color: yellow;
		}
	 .no60 {
		width: 8rem;
		height: 8rem;
		text-align: center;
		line-height: 8rem;
		background-color: olive;
		}

效果图:


justify-content: flex-start;


justify-content: space-around;


justify-content: center;


3.align-items: flex-end | flex-start | center (属性定义项目在交叉轴上如何对齐)

html:

		<div class="center">
			<div class="Onemain">
				<div class="one">1</div>
				<div class="two">2</div>
				<div class="three">3</div>
				<div class="four">4</div>
			</div>
			<div class="Twomain">
				<div class="one">1</div>
				<div class="two">2</div>
				<div class="three">3</div>
				<div class="four">4</div>
			</div>
			<div class="Threemain">
				<div class="one">1</div>
				<div class="two">2</div>
				<div class="three">3</div>
				<div class="four">4</div>
			</div>
		</div>

css:

.center {
				display: flex;
				border: 0.126666rem solid black;
				justify-content: space-between;
				text-align: center;
			}
			
			.Onemain {
				display: flex;
				align-items:flex-start ;
				border: 0.013333rem solid black;
			}
			
			.Twomain {
				display: flex;
				align-items:center ;
				border: 0.013333rem solid black;
			}
			
			.Threemain {
				display: flex;
				align-items: flex-end;
				border: 0.013333rem solid black;
			}
			
			.one {
				width: 5rem;
				height: 6rem;
				background-color: red;
			}
			
			.two {
				width: 5rem;
				height: 2rem;
				background-color: black;
			}
			
			.three {
				width: 5rem;
				height: 4rem;
				background-color: green;
			}
			
			.four {
				width: 5rem;
				height: 9rem;
				background-color: tomato;
			}
			

效果图:




希望大家多多支持偷笑偷笑,后续。。。。。。



  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值