之前的div标签可以使用margin:0 auto进行居中
但是,如果该标签被设置了定位,则无法居中了.
position: absolute;
margin: 0 auto;
/* 有绝对定位属性时,居中属性 margin: 0 auto;不生效 */
这个时候需要采取下面两种办法使其居中:
1/先把标签左边定位到中间线上,然后设置外边距
position: absolute;
left: 50%;
top: 50%;
margin-left: -250px;
margin-top: -250px ;
2/
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
定位的层级关系:
定位标签发生重叠时,body中标签后来居上,
如果设置了z-index属性,z-index属性值越大,越靠上.未设置时默认为0
.