如何移动包含文本的div的image / div标记中心

时间:2014-08-28 07:50:10

标签: javascript jquery html css css3

我有这样的标记

<p>
    <img hspace="4" alt="" src="sampleimage.png">

    Many in her village believed that girls should not be educated, and someone burned down the coffee trees on Enatha’s family farm – their only source of income – to discourage her from continuing with her studies.&nbsp;However, Enatha’s parents continued to support her education, and in 2011, she earned a spot at the Gashora Girls’ Academy of Science and Technology.

</p>

我通过向图像添加float-right添加了文本环绕图像效果。目前文字环绕图像,但图像位于顶部。

当前快照 enter image description here

我希望图像位于文本中间(文本中间2行)。无论如何要实现这样的目标

预期行为 enter image description here

2 个答案:

答案 0 :(得分:1)

对于仍在疑惑的人,我通过以下stackoverflow接受的答案获得了解决方案

How to make text wrap above and below a div?

答案 1 :(得分:0)

最接近的是将图像放在段落中。但是,确切的位置将取决于图像之前的文本如何包装,这取决于您控制之外的许多因素(例如文本大小,字体,可用宽度以及最重要的是浏览器和操作系统之间的微小字体渲染差异)。

<p>

    Many in her village believed that girls should not be educated, and someone burned down the coffee trees on Enatha’s family farm – their only source of income – to discourage her from continuing with her studies.&nbsp;

    <img hspace="4" alt="" src="sampleimage.png">

    However, Enatha’s parents continued to support her education, and in 2011, she earned a spot at the Gashora Girls’ Academy of Science and Technology.

</p>