设置弹性容器的
主轴对齐属性:justify-content:center
交叉轴的对其属性:align-items:center
.perent{ position: absolute; display: flex; display: -webkit-flex; width: 500px; height:500px; justify-content: center; align-items: center; background: green; flex-direction: row-reverse; flex-wrap: wrap; justify-content: center; align-items: center; } .left,.right{ flex:1 1 200px; width: 100px; height: 100px; background: red; } .middle{ flex-grow: 1; height: 100px; background: blue; }
设置父元素position:absolute或者relative;
设置该元素:position:absolute;
left:50%;
right:50%;
margin-left:-该元素的边长0.5倍
margin-top:-该元素的边长0.5倍
.con{ position: absolute; width: 200px; height: 200px; bottom: 0; background: green; } .middle{ width: 100px; height: 100px; background: blue; position: absolute; left:50%; top:50%; margin-left: -50px; margin-top: -50px; }
设置要对齐的元素的
position:fixed;
left:0;
right:0;
top:0;
bottom: 0;
margin: auto;
.middle{ /*flex-grow: 1;*/ width: 100px; height: 100px; background: blue; position: fixed; left:0; right:0; top:0; bottom: 0; margin: auto; }
引入弹性盒布局模型的目的是提供一种更加有效的方式来对一个容器中的子元素进行排列、对齐和分配空白空间。
如对本文有疑问, 点击进行留言回复!!
清除新版Google Chrome浏览器中表单控件(input,button...)默认的黑色边框
荐 20200714——git/mac配置/项目运行步骤/一些报错
antd 菜单组件 使用时报错:Cannot read property ‘isRootMenu‘ of undefined
CSS|div的style=“background-image: url(img/a.bmp)图片显示不出来
硬件仪表盘账号建立指导(一) --WHQL认证测试结果提交账号(一)
cookie的规范Cookie的不可跨域名性或Cookie与域名的关系
网友评论