元素水平垂直居中

元素自身定位
div {     width: 100px;     height: 100px;     position: absolute;     top: 0;     right: 0;     bottom: 0;     left: 0;     margin: auto; }
或div {     width: 100px;     height: 100px;     position: absolute;     top: 50%;    left: 50%;     transform: translate(-50%,-50%);  }
父级使用flex
.parent {     display: flex;     justify-content: center;     align-items: center; }
posted @ 2021-12-29 16:41  Re。  阅读(26)  评论(0)    收藏  举报