主要用于弹出框,用css实现。
核心思路:
第一步:定位到屏幕中央,即top和height都用50%
第二步:用margin的负值,使div向上和向左分别移动高度和跨度的一半。
div {
position: absolute;
top: 50%;
left: 50%;
margin: -150px 0 0 -200px;
width: 400px;
height: 300px;
background-color: #CCC;
}
核心思路:
第一步:定位到屏幕中央,即top和height都用50%
第二步:用margin的负值,使div向上和向左分别移动高度和跨度的一半。