CSS弹性盒模型——display:flex

弹性盒模型也叫flex布局

弹性盒模型是CSS属性

flex使用方式

选择器{
	display:flex;
}

直接上Demo

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        div{
            display:flex;
            border: 1px solid black;
        }
        li{
            width: 20%;
            height: 200px;
            list-style: none;
        }
        #one{
            background-color: red;
        }
        #two{
            background-color: aqua;
        }
        #three{
            background-color: green;
        }
    </style>
</head>
<body>
    <div>
        <li id="one"></li>
        <li id="two"></li>
        <li id="three"></li>
    </div>
</body>
</html>

效果图:
在这里插入图片描述
可以看见,div标签是li标签的父标签,而且div是弹性盒模型,弹性盒模型内的元素自然排列是横排,块级元素在弹性盒模型内也是横排显示

使用flex布局的元素可以使用一些关于弹性盒模型的属性。

flex-direction属性

设置主轴的反向。

row——默认,主轴从左到右

div{
    display:flex;
    flex-direction: row;
}

效果图:
在这里插入图片描述
row-reverse——主轴从右向左布局

div{
	display:flex;
	flex-direction:row-reverse;
}

效果图:
在这里插入图片描述
column——主轴纵向排列

div{
	display:flex;
	flex-direction:column;
}

效果图:
在这里插入图片描述
column-reverse——反向的主轴纵向布局

div{
	display:flex;
	flex-direction:column-reverse;
}

效果图:
在这里插入图片描述

justify-content属性

内容元素根据主轴布局

flex-start——内容位于主轴开始位置

div{
	display:flex;
	flex-direction:row;
	justify-content:flex-start;
}

效果图:
在这里插入图片描述
flex-end——内容位于主轴尾部

div{
	display:flex;
	flex-direction:row;
	justify-content:flex-end;
}

效果图:
在这里插入图片描述
center——内容位于主轴中间

div{
	display:flex;
	flex-direction:row;
	justify-content:center;
}

效果图:
在这里插入图片描述

space-between——平均分布,第一个与最后一个内容元素紧贴父元素

div{
	display:flex;
	flex-direction:row;
	justify-content:space-between;
}

效果图:
在这里插入图片描述
space-around——平均分布,但第一个与最后一个内容元素并非紧贴父元素

div{
	display:flex;
	flex-direction:row;
	justify-content:space-around;
}

效果图:
在这里插入图片描述

align-items属性

内容元素根据副轴布局

flex-start——内容元素位于副轴的开头

div{
	display:flex;
	flex-direction:row;
	align-items:flex-start;
}

效果图:在这里插入图片描述

flex-end——内容元素位于副轴的尾部

div{
	display:flex;
	flex-direction:row;
	align-items:flex-end;
}

效果图:
在这里插入图片描述
center——内容元素位于副轴的中间

div{
	display:flex;
	flex-direction:row;
	align-items:center;
}

效果图:
在这里插入图片描述

flex-wrap属性

设置内容元素是否多行

nowrap——内容元素即使宽过父元素也是单行

div{
	display:flex;
	flex-direction: row;
	flex-wrap:nowrap;
}

效果图:
在这里插入图片描述
warp——内容元素宽于父元素时,多余的内容元素会在第二行

div{
	display:flex;
	flex-direction: row;
	flex-wrap:wrap;
}

效果图:
在这里插入图片描述

wrap-reverse——内容元素宽于父元素时,多余的内容元素会在第二行,但是翻转

div{
	display:flex;
	flex-direction: row;
	flex-wrap:wrap-reverse;
}

效果图:
在这里插入图片描述


弹性盒模型常用的属性就写到这里~

欢迎大家补充~

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值