当前位置:首页 > 技术分享 > 正文内容

Flex布局属性详解 左对齐 右对齐

admin2年前 (2023-10-12)技术分享2377

 flex布局利用修改父元素display:flex实现


1 、   flex-direction属性


        取值:row(默认)|| row-reverse || column || column-reverse


        解释:row为横向排列,顺序为1-2-3. row-reverse为横向排列,但顺序为3-2-1. column为纵向排列,顺序为1-2-3. column-reverse为纵向排列,但顺序为3-2-1

<style>
      * {
        margin: 0;
        padding: 0;
      }
      .main {
        width: 900px;
        height: 100px;
        display: flex;
        flex-direction: column-reverse;
      }
      .box1,
      .box2,
      .box3 {
        width: 300px;
        height: 100px;
        text-align: center;
      }
</style>
<body>
    <div class="main">
      <div class="box1" style="background-color: red">1</div>
      <div class="box2" style="background-color: green">2</div>
      <div class="box3" style="background-color: blue">3</div>
    </div>
</body>

2、     flex-wrap属性


取值:nowrap(默认) || wrap || wrap-reverse


解释:nowrap表示不换行,wrap表示换行,wrap-reverse表示换行,第一排紧紧贴在容器底部。


3、     justify-content属性


取值:flex-start(默认)|| flex-end || center || space-between || space-around


解释:表示横轴对齐方式:flex-start表示左对齐,flex-end为右对齐,center居中对齐,space-between表示左右两端对齐,space-around为项目之间间距为左右两侧项目到容器间距的2倍


3、     align-items属性


取值:flex-start || flex-end || center || baseline || stretch(默认)


解释:表示纵轴排列方式:stretch表示不设置高度,占满整个屏幕。flex-start表示纵轴紧贴容器顶部。center表示在纵轴中心排列。flex-end表示紧贴容器底部。baseline表示以第一行文字的基线为参照


4、    align-content属性

表示多行项目的对齐方式,和align-item一样


5、      一行固定个数,超出换行(流式布局)

.father{
	width: 100%;
	display: flex;
	flex-wrap: wrap;
	justify-content: flex-start;
}
.child{
	/* 方法一 */
	flex: 1;
	height: 50px;
	margin: 0 5px 5px 0;
	background-color: #999;
	width: calc((100% - 10px) / 3);// 这里的10px = (分布个数3-1)*间隙5px, 可以根据实际的分布个数和间隙区调整
	min-width: calc((100% - 10px) / 3);// 加入min-width、max-width后每个child的宽度就生效了
	max-width: calc((100% - 10px) / 3);
	
	/* 方法二 */
	/* 
		height: 50px;
		margin: 0 5px 5px 0;
		box-sizing: border-box;
		background-color: #999;
		flex: 0 0 calc((100% - 10px) / 3);
	*/
}
.child:nth-child(3n){
	margin-right: 0;// 去除第3n个的margin-right
}


扫描二维码推送至手机访问。

版权声明:本文由小刚刚技术博客发布,如需转载请注明出处。

本文链接:http://blog.bitefu.net/post/550.html

标签: cssflex
分享给朋友:

相关文章

php高效检测远程图片是否存在

php高效检测远程图片是否存在function img_exits($url){     $ch = curl_init();    &...

PIP 更换国内安装源linux/windows

pip国内的一些镜像  阿里云 http://mirrors.aliyun.com/pypi/simple/   中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/   豆瓣(...

安卓模拟器连接端口 及常用命令

下面是我总结和测试通过的:有的是搜集来的模拟器名称                     &nbs...

python3 selenium webdriver.Chrome php 爬取汽车之家所有车型详情数据[开源版]

介绍本接口是车型库api的补充,用于爬取汽车之家所有车型详情数据开源地址:https://gitee.com/web/CarApi/tree/master/python软件架构python3 selenium webdriver.Chrom...

python 高速处理分析超大网站日志文件 带进度条手动输入日志文件

 python 高速处理分析超大网站日志文件 带进度条手动输入日志文件    1 统计本日志文件的总pv、uv    2 列出全天每小时的pv、uv数    3 列出to...

记一次阿里云服务器cc攻击防护 windows 2012 iis8

记一次阿里云服务器cc攻击防护 windows 2012 iis8

上次连续一周左右阿里云服务器都在遭受cc攻击.导致访问量特别大,节假日接口调用特别缓慢或者根本访问不了的情况.本身服务器安装了 网站安全狗(IIS版) .并开始了防cc攻击.但是呢,平时还行,这次压力山大.于是一气之下用pytho...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。