CSS中怎么用flex实现div水平垂直居中
Admin 2022-06-24 群英技术资讯 1053 次浏览
今天小编跟大家讲解下有关“CSS中怎么用flex实现div水平垂直居中”的内容 ,相信小伙伴们对这个话题应该有所关注吧,小编也收集到了相关资料,希望小伙伴们看了有所帮助。一、flex-direction: (元素排列方向)
※ flex-direction:row (横向从左到右排列==左对齐)

※ flex-direction:row-reverse (与row 相反)

※ flex-direction:column (从上往下排列==顶对齐)

※ flex-direction:column-reverse (与column 相反)

二、flex-wrap: (内容一行容不下的时候才有效)
※flex-wrap:nowrap (超出不换行,很奇怪里面的宽度会变成100%)

※ flex-wrap:wrap (超出按父级的高度平分)

※flex-wrap:wrap-reverse(与wrap 相反)

三、justify-content: (水平对齐方式)
※flex-start (水平左对齐)

※ justify-content:flex-end; (水平右对齐)

※ justify-content:center;(水平居中对齐)

※justify-content:space-between; (两端对齐)

※justify-content:space-around; (两端间距对其)

四、align-items: (垂直对齐方式)
※ align-items:stretch; (默认)

※align-items:flex-start; (上对齐,和默认差不多)

※align-items:flex-end; (下对齐)

※ align-items:center;(居中对齐)

=※align-items:baseline; (基线对齐)
如弹性盒子元素的行内轴与侧轴(纵轴)为同一条,则该值与'flex-start'等效。其它情况下,该值将参与基线对齐。
flex容器属性
/*1.方向*/
/*默认方向(row正方向)*/
/* flex-direction: row; */
/*row反方向*/
/* flex-direction: row-reverse; */
/*columnz正方向*/
/*flex-direction: column;*/
/*columnz反方向*/
/*flex-direction: column-reverse;*/
/*2.换行*/
/*flex-wrap: wrap;*/
/*flex-wrap: wrap-reverse;*/
/*3.direction+wrep组合*/
/*flex-flow: row wrap-reverse;*/
/*4.主轴对齐*/
/*起点左对齐*/
/*justify-content: flex-start;*/
/*起点右对齐*/
/*justify-content: flex-end;*/
/*起点居中对齐*/
/*justify-content: center;*/
/*间隔左右分散*/
/*justify-content: space-between;*/
/*间隔内边距相等*/
/*justify-content: space-around;*/
/*间隔相等*/
/*justify-content: space-evenly;*/
/*5.交叉轴对齐 当flex-direction: row;修饰y轴, 当flex-direction: column;修饰x轴*/
/*默认交叉轴对齐*/
/*align-items: stretch;*/
/*默认交叉轴居中*/
/*align-items: center;*/
/*默认交叉轴上对齐*/
/*align-items: flex-start;*/
/*默认交叉轴下对齐*/
/*align-items: flex-end;*/
/*默认交叉轴内容对齐*/
/*align-items: baseline;*/
/*6.多行交叉轴对齐*/
/*align-content: stretch;*/
/*多行交叉轴居中对齐*/
/*align-content: center;*/
/*多行交叉轴上对齐*/
/*align-content: flex-start;*/
/*多行交叉轴下对齐*/
/*align-content: flex-end;*/
/*多行交叉轴内边距相等*/
/*align-content: space-around;*/
/*多行交叉轴间隔左右分散*/
/*align-content: space-between;*/
/*多行交叉轴间隔相等*/
/*align-content: space-evenly;*/
flex项目属性
/*1.控制项目次序*/
/*order: 2;*/
/*2.按比例扩大空间,数越大空间越大,0值不扩大*/
/*flex-grow: 2;*/
/*3.按比例缩小空间,数越大空间越小,0值不压缩*/
/*flex-shrink: 2;*/
/*4.需要flex-direction配合使用,row=宽 column=高,并且优先级高于width hight, auto值 让位优先级*/
/*flex-basis: 600px;*/
/*5.flex=grow+shrink+basis*/
/*grow =1 && shrink = 1 && basis = auto*/
/*flex: auto;*/
/*grow =0 && shrink = 1 && basis = auto*/
/*flex: initial;*/
/*grow =0 && shrink = 0 && basis = auto*/
/*flex: none;*/
/*6.align-self覆盖容器的align-items*/
/*align-self: flex-start;*/!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
这篇文章主要介绍了CSS3 mask 遮罩的具体使用方法,详细的介绍了CSS3 mask 遮罩的具体使用,具有一定的参考价值,有兴趣的可以了解一下
css如何设置不可点击?可以通过设置元素的pointer-events属性设置为none,来实现元素不可点击。此方法是通过设置元素的鼠标事件失效来实现元素不可点击。
在css中更改按钮中字体大小的方法1、首先,在页面中创建两个按钮,并定义class类用于对比; <body> <button type="button" class="btn">字体为20px</button> <button type="b
这篇文章主要介绍了CSS3 二级导航的制作的示例的相关资料,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
这篇文章主要介绍了3种方式实现瀑布流布局小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008