如何在左边显示图像和在同一行右边显示段落

时间:2013-09-19 13:05:54

标签: html inline-code

我想做内联html样式,我想要一个图像向左浮动,并且右边的段落在同一行上,但是我没有得到下面代码所需的结果:

我的代码在下方或请查看jsFiddle

的index.html

<div class="newWrapper">
    <div class="person1" style="float:left; display:inline-block; ">
        <img src=simonwilliams.jpg width="auto" height"auto" clear:both;/>
        <p style="float:right; display:block;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer arcu mauris, ullamcorper et ligula vitae, hendrerit sodales tellus. Maecenas quis pulvinar lacus.</p>
    </div>

    <div class="person2" style="float:left" display:inline-block;>
        <img src=simonwilliams.jpg width="auto" height"auto"/>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer arcu mauris, ullamcorper et ligula vitae, hendrerit sodales tellus. Maecenas quis pulvinar lacus.</p>
    </div>
</div>

2 个答案:

答案 0 :(得分:3)

添加范围并将其设为float:left,并添加<p>标记的范围并将其设为float:right。同时,如果你想为下面的div做同样的事情,你也可以这样做。

 <div class="person1" style="float:left; display:inline-block; ">
        <span style="float:left;width: 20%;">
            <img src="http://www.ninahale.com/wp-content/uploads/2013/08/Google.jpg"  
             width="70" height"70" />
        </span>
        <span style="float:right;width: 80%;">
            <p style="float:right; display:block;">Lorem ipsum dolor sit amet,    
                    consectetur adipiscing elit. Integer arcu mauris, ullamcorper et 
                    ligula vitae, hendrerit sodales tellus. Maecenas quis pulvinar 
                    lacus.
            </p>
        </span>
 </div>

Demo

答案 1 :(得分:1)

桌子和两个TD怎么样?

   <div>
    <table>
        <td><img src=simonwilliams.jpg width="auto" height"auto" clear:both;/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer arcu mauris, ullamcorper et ligula vitae, hendrerit sodales tellus. Maecenas quis pulvinar lacus.
        </td>
        <td>
<img src=simonwilliams.jpg width="auto" height"auto" clear:both;/>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer arcu mauris, ullamcorper et ligula vitae, hendrerit sodales
  tellus. Maecenas quis pulvinar lacus.
        </td>
    </table>
</div>