我怎么能把蓝色盒子放在红色盒子的中心?我看到蓝色框的左侧正好在红色框的中间,但我想将整个蓝色框居中,而不是左侧。盒子的尺寸不是恒定的。无论盒子尺寸如何,我都想对齐。在这里玩的例子。谢谢 !
HTML:
<div id="rel">
<span id="abs">Why I'm not centered ?</span>
</div>
CSS:
#rel {
position: relative;
top: 10px;
left: 20px;
width: 400px;
height: 300px;
border: 1px solid red;
text-align: center;
}
#abs {
position: absolute;
bottom: 15px;
width: 300px;
height: 200px;
border: 1px solid blue;
}