固定定位position:fixed实现高度自适应

position:fixed实现高度自适应
直接上样式

.mask {
/*需要宽度*/
  width: 70%;
  background-color: white;
  position: fixed;
  left: 50%;
  top: 50%;
  /* 支持现代浏览器 */
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}

当使用:top: 50%;left: 50%;, 是以左上角为原点,故不处于中心位置 translate(-50%,-50%) 作用是,往上(x轴),左(y轴)移动自身长宽的 50%,以使其居于中心位置。

猜你喜欢

转载自blog.csdn.net/ruffaim/article/details/79577924