代码之家  ›  专栏  ›  技术社区  ›  SetiSeeker

带图像和可变长度文本的浮动div

  •  1
  • SetiSeeker  · 技术社区  · 14 年前

    我有一个问题,使我的HTML格式,我也需要它的方式。

    我正在动态创建div(父)。每个div中都有两个div(div one&two)。

    Div one是可以是任意长度或可变长度的文本。第二部分包含一个图像。

    无论父div的大小如何,文本都需要尽可能地填充宽度。但我需要图像的第二个div,在行末尾的文本上方浮动。我还需要所有的图像div,垂直排列。

    这个父div是可重新调整大小的,可以变小或变大,但浮动图像必须始终位于句子行中,但在容器的右侧。

    如果文本比div父容器宽,则图像需要在父容器的右侧与文本在同一行上浮动。如果文本小于父div,则图像必须仍位于父div的右侧。

    如果有意义的话,可以把它想象成一个浮动的图像完全停止。每个句子的句号都在一条长的垂直线上。

    我试过沙发床和桌子,但结果都不清楚。

    这是我当前的代码:

      <div>
        <div style="display: inline; float: left;">
            Text Goes here</div>
        <div style="display: inline; float: right; z-index: 1000;">
            <img src="info.png" /></div>
    </div>
    <div>
        <div style="display: inline; float: left;">
            Next line of Text Goes here</div>
        <div style="display: inline; float: right; z-index: 1000;">
            <img src="info.png" /></div>
    </div>
    

    谢谢

    1 回复  |  直到 11 年前
        1
  •  0
  •   KcSchaefer    14 年前

    我觉得很难想象你想要得到什么结果。你能画一张图表说明你想要的结果吗?

    据我所知,您正在寻找这个(在JSFiddle查看结果): http://jsfiddle.net/kcschaefer/GYQea/9/

    代码是:

    <div id="parent" style="width: 100%;">
    <div>
            First text goes here
             <img src="http://www.kendraschaefer.com/images/info.png" style="float:right; z-index: 1000;" />
    <div>
        <div style="clear: both;"></div>
    
    <div>
            Next line of  really long text that demonstrates how the float will work would go  right here, and you can see that the info thingie goes all the way to  the end of the div, no matter how long this is.
             <img src="http://www.kendraschaefer.com/images/info.png" style="float:right; z-index: 1000;" />
    
    <div>
    </div><!-- end parent -->