我有以下代码:如何向上移动内部盒子并使用CSS保留外部盒子?
<html>
<head>
<style>
#yellow {height:100px; background:yellow;}
#blue {background:blue;}
#red {background:red; width: 400px; height: 100px; margin:0px auto;}
</style>
</head>
<body>
<div id="yellow"></div>
<div id="blue">
<div id="red">Lots of content goes in here that will expand the outer blue box as well</div>
</div>
</body>
</html>
我想要的红色框,以便它重叠的黄色盒子和蓝盒子都向上移动约30像素。当我试图做一个#red {margin:-30px auto 0px auto;}
时,蓝色盒子也随着红色盒子向上移动了30个像素,尽管我想让蓝色盒子保持原位。
我如何让红框向上移动并重叠黄色和蓝色?
如果您不希望#blue底部的空格,请将margin-bottom:-30px添加到#red。 – 2012-02-23 21:25:01