flex布局中经常有其他元素靠左排列,最后一个元素靠右排列的设计。简单的在最后一个元素中添加
margin-left:auto
的样式,就可以实现
MDN中给出了说明
剩余空间会自动分配给该元素。
margin的其他注意事项:
- margin的百分比依据的是父元素的宽度
- 边距折叠
- 水平垂直居中中的使用(position)
.box {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
}