![4a2ac9eab6432a7e4ce5dc658ed1ad9a.png](https://img-blog.csdnimg.cn/img_convert/4a2ac9eab6432a7e4ce5dc658ed1ad9a.png)
英文:http://1linelayouts.glitch.me/
译文:https://juejin.im/post/6847902221779238920
![7b554c86af384ac3c3733d71292b13c4.png](https://img-blog.csdnimg.cn/img_convert/7b554c86af384ac3c3733d71292b13c4.png)
超级小中
在没有 flex 和 grid 之前,垂直居中一直不能很优雅的实现。而现在,我们可以结合 grid 和 place-items 优雅的同时实现水平居中和垂直居中。
class="parent blue" > <div class="box coral" contenteditable>
:)
div>
.ex1 .parent {
display: grid; place-items: center; }
![1fa0f78d971e81538e1e38e706242cc3.gif](https://img-blog.csdnimg.cn/img_convert/1fa0f78d971e81538e1e38e706242cc3.gif)
源码地址:
https://codepen.io/una/pen/YzyYbBx
![7ee977793821b95a70e6e4d3ac6b06d7.png](https://img-blog.csdnimg.cn/img_convert/7ee977793821b95a70e6e4d3ac6b06d7.png)
可解构的自适应布局(The Deconstructed Pancake)
flex: 0 1 <baseWidth>
这种布局经常出现在电商网站:
在视口足够的时候,三个框固定宽度横放;
在视口不够的时候(宽度在移动上面),宽度仍然固定,但是自动解构(原谅我的中文水平),不在同一水平面上。
class="parent white">
class="box green">1
class="box green">2
class="box green">3
.ex2 .parent {
display: flex; flex-wrap: wrap; justify-content: center; } .ex2 .box {
flex: 1 1 150px; /* flex-grow: 1 ,表示自动延展到最大宽度 */ flex: 0 1 150px; /* No stretching: */ margin: 5px; }
![0a7a4c986953f339364d13ee08578fb6.gif](https://img-blog.csdnimg.cn/img_convert/0a7a4c986953f339364d13ee08578fb6.gif)
当我们设置flex: 1 1 150px;时候:
![572392d79ef2ca1ff664ee22baa36512.gif](https://img-blog.csdnimg.cn/img_convert/572392d79ef2ca1ff664ee22baa36512.gif)
源码地址:
https://