响应式元素居中

2018-11-08  本文已影响16人  索隆萨克

当前元素box,宽度为width,高度为height
注意:父元素设置position:relative;

// 左右居中
.box{
  position:absolute;
  left:calc(50% - width/2);
}
// 垂直居中
.box{
  position:absolute;
  top:calc(50% - height/2);
}
上一篇 下一篇

猜你喜欢

热点阅读