我有一个基本的设置,如下所示:
.container {
border:1px solid green;
}
<div class="container">
<div class="parent">
Hello world! I don't want to overlap with the image. Hello world! I don't want to overlap with the image. Hello world! I don't want to overlap with the image.
</div>
<div class="parent">
<div class="child">
<img src="http://i.imgur.com/sQSbV8o.jpg" width="200" height="200">
</div>
</div>
</div>
我想将 .child
div 对齐到 .container
的右上方。我想要实现这个目标,不使用 position:fixed
或一些 margin-top:-px
的 hack,也不改变任何 HTML。
这是否可行?
我尝试过的方法
我可以给
.child
div 设置float:right
,但显然第一个父 div 在它上面。我可以给
.child
div 设置position:absolute
,并且设置top:0
和right:0
,但它会明显重叠。也许
flex-box
可以解决问题?尽管存在兼容性问题...
.child
同级的内容,并且您希望该段落的文本仍然左对齐。 - Michael Benjamin