我认为你想要的是这样的:
<div id = "parent">
<div id = "child"></div>
</div>
#parent {
position: relative;
width: 500px;
height: 500px;
background: red;
display: block; /* fix for opera and ff */
}
#child {
position: absolute;
width: 100px;
height: 100px;
background: blue;
top: 0;
left: 100%; /* this line of code will sort things out for you :) */
}
<div>
(而是span或其他内联元素),请不要忘记为Opera(Presto)和FF添加display:block
。 - Ivan Black就这么简单吗?
CSS:
div {border:1px solid #000}
.p {
position:relative;
width:100px; /*width will be unknown*/
height:80px;
background:#999;
}
.c {
position:absolute;
width:40px;
height:30px;
background:red;
top:0;
left:100%;
}
HTML:
<div class="p">
<div class="c"></div>
</div>