标签:
1. 显示的设定子元素的宽度,然后将资源的margin值设定为:margin:0 auto;
html:
<div class="parent"> <div class="child"></div> </div>
css:
.parent {
width:100px;
height:100px;
background:red;
}
.child {
/*如果设定为绝对定位,会不起效
* 原因是设定为觉得定位后,元素的位置会相对于
*向上回溯第一个定位为:absolute/relative
*的父级元素定位
*/
/*position: absolute;*/
margin:0 auto;
width:50px;
height:100px;
background:green;
}
2.
标签:
原文地址:http://www.cnblogs.com/alicePanZ/p/4404345.html