子div在父div中居中
方法一(使用绝对布局):
弊端:必须要知道这个容器的长宽,因为在子元素中的 margin-top:-100px; margin-left:-100px; 这两个样式分别是子元素长、宽的一半
.father {
width: 500px;
height: 500px;
position: relative;
background-color: red;
}
.son {
width: 200px;
height: 200px;
position: absolute;
top: 50%;
left: 50%