没有固定高度的div,在父元素中垂直居中

如图,我要做的效果是将中间蓝色的地方,也就是这个.stopover-station标签,上下垂直居中,只要在需要居中的父元素上设置

.operate-mask-outer>#operateMask {
  align-items: center;
  display: -webkit-flex;
}

利用弹性盒子来居中:

align-items: stretch|center|flex-start|flex-end|baseline|initial|inherit;

align-items的值有很多,其中center是代表该元素位于容器的中心。弹性盒子元素在该行的侧轴(纵轴)上居中放置。(如果该行的尺寸小于弹性盒子元素的尺寸,则会向两个方向溢出相同的长度)。

其他的值详见http://www.runoob.com/cssref/css3-pr-align-items.html

猜你喜欢

转载自blog.csdn.net/Hero_rong/article/details/84572304