答案 0 :(得分:17)
我想你想要这样的东西
<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 :) */
}
答案 1 :(得分:3)
这很简单吗?
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>