css - 将文本 float 在图像上,右对齐

标签 css image text css-position

我有几个嵌套的 div,我试图在图像的右下角 float 一些文本,然后在图像的右侧放置更多文本。 float 文本显示在整行的右侧,而不是图像的右侧。整个内容(连同其他文本)被包裹在一个大 div 中,如果我添加 bottom:0px,我想要 float 的文本就会显示在它的底部。

应该是(图片右下角有数字)

[_1] 标题

但是我得到了

[_] 标题 1

HTML

<div>
    <div class='outerwrapper'>
      <div class='innerwrapper'>
        <img src='image.jpg'>
        <div class='floatedtext'>1</div>
      </div>
      <div class='caption'>image caption to the right<br></div>
    </div>
</div>

CSS

.outerwrapper
{
  clear: both;
  min-height: 45px;
  margin-left: 10px;
}
.innerwrapper
{
   clear:both;
}
.caption
{
   font-size:13px;
}
.floatedtext
{
   font-size:12px;
   position: absolute;
   right:0px;
   text-align:right;   
}

最佳答案

innerwrapper 类需要相对位置

http://jsfiddle.net/8SDvu/

这是它的基础,您可能想在需要的地方添加一些填充和边距,但我相信您可以弄清楚这些

.innerwrapper
{
   clear:both;
   position: relative;
   float: left;
}

可能要添加

.floatedtext {
   bottom: 0;
}

关于css - 将文本 float 在图像上,右对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16490095/

相关文章:

html - 如何在 Red Hat Linux 中的 HTML 文档中插入图像?

batch-file - xcopy 循环复制 .txt 文件

Android:更改标题栏中的对齐方式

html - 固定标题不会随正文水平滚动

wpf - WPF中的自定义文字包装

html - 在移动其他 DIV 的位置之前将 DIV 的大小调整为最小值

html - Div类定位

html - CSS - 将图像放置在文本旁边

css - Safari 选择选项中的两个点而不是复选标记

iphone - 从图像中读取文本 iPhone SDK