css“left”不工作
问题描述:
我有两个div,父母和子女,我想让那个孩子的左边(左边框)将在父母的中心。
I have 2 divs, parent and child, I want that child left side (left border) will in center of parent.
为什么这个代码不工作? left:50%
for child,is not working。
Why this code not working? that is left: 50%
for child, is not working.
<div id="outher">
<div id="inner">
</div>
</div>
css:
#outher {
width: 1000px;
height: 1000px;
background-color: #ccc;
}
#inner {
width: 400px;
height: 300px;
background-color: #090;
left: 50%;
}
答
您需要设置位置到绝对
或相对
:
#inner {
width: 400px;
height: 300px;
background-color: #090;
position: absolute;
left: 50%;
}