每次我尝试在 CSS 中做一些看似简单的事情时,它都不起作用。
我有一个包含 460x160 图像的内容 div。我想要做的就是将图像放在右下角并将我的文字环绕在它周围。
<div id="contents">
<img src="..." />
text text text text text text ...
</div>
所以我希望它看起来像:
------------------
| text text text |
| text text text |
| text text -----|
| text text | |
------------------
用左上角或右上角的图像做这件事很简单:
#contents img { float:right; }
------------------
| text text | |
| text text -----|
| text text text |
| text text text |
------------------
现在我该如何把它推到底部?到目前为止,我想出的最好的是:
#contents img { float:right; margin-top: 90%} // really needs to be 100%-160px
------------------
| text text |
| text text |
| text text -----|
| text text | |
------------------
在这种情况下,文本不会打印在边距中,因此图像上方有空白。
#contents { position:relative; }
#contents img { position:absolute; right:0; bottom:0; }
-or-
// move the img tag under the text in the html and:
#contents img { float:right; margin-top:-160; }
------------------
| text text text |
| text text text |
| text text -----|
| text text | te |
------------------
在这种情况下,文本打印在图像上方或下方。
那么......我怎样才能做到这一点?