简体   繁体   English

div周围浮动的文本

[英]Text floating around a div

Im trying to make text flowing around the image, in a different scenario. 我试图在不同的情况下使文本在图像周围流动。 the image wont be inside the content. 图像不会在内容中。 Image would be a seperate component and the div with text will be a seperate component. 图像将是一个单独的组件,带有文本的div将是一个单独的组件。 So markup will look like this 所以标记看起来像这样

<img class="imgtofloat" src="images/1.png" alt="" />
<div class="divwithcontent">
 <p>Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum </p>
</div>

The scenario is that we cant change the markup but we need to position the image between the content and make the content float around it. 场景是我们无法更改标记,但是我们需要将图像放置在内容之间,并使内容在其周围浮动。

EDIT 1: I need the image to be in the center of the content as it is in this image https://www.flickr.com/photos/41695354@N08/14477076543/ 编辑1: 我需要图像位于内容的中心,因为它在此图像中https://www.flickr.com/photos/41695354@N08/14477076543/

We can stretch our CSS imagination. 我们可以扩展CSS的想象力。 Hide the image and replace it with background. 隐藏图像并将其替换为背景。

Example, possibly adaptable. 例如,可能适应。

Have a fiddle! 小提琴!

CSS CSS

img {
    display: none;
}
p:first-child:after {
    content: "";
    display: block;
    float: left;
    width: 100px;
    height: 100px;
    background: url(http://www.placehold.it/100) no-repeat;
    margin: 20px;
}

If you can Change the image placement. 如果可以,请更改图像位置。 step 1) put image in between the paragraph text. 步骤1)将图片放在段落文字之间。 step 2) and one attribute in img tag align="left" 第2步)和img标签中的一个属性align =“ left”

如果您只有一些CSS规则,也可以使用内联样式。

<img src="images/1.png" alt="" style="float: left" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM