Floating Elements Under Tags in CSS
Let's say we now have two paragraphs and an image placed in the first paragraph. Let's say this image has a float property set to right, and also a translucency:
<div>
<p>
<img src="img.png" alt="">
Lorem ipsum dolor sit amet, consectetur adipiscing elitorire.
</p>
<p>
some long text
</p>
</div>
div {
border: 1px solid red;
text-align: justify;
}
p {
border: 1px solid green;
}
img {
float: right;
opacity: 0.5;
}
:
Now let's put an image in the HTML code after the first paragraph and see what happens:
<div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elitorire.
</p>
<img src="img.png" alt="">
<p>
some long text
</p>
</div>
div {
border: 1px solid red;
text-align: justify;
}
p {
border: 1px solid green;
}
img {
float: right;
opacity: 0.5;
}
:
As we can see, the text of the second paragraph flows around the image, but not the first.
Let's move our image after the second paragraph. In this case, it will float to the right, but there will be no flow:
<div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elitorire.
</p>
<p>
some long text
</p>
<img src="img.png" alt="">
</div>
div {
border: 1px solid red;
text-align: justify;
}
p {
border: 1px solid green;
}
img {
float: right;
opacity: 0.5;
}
:
It turns out that only those elements that are below the image will flow around it, but not those that are above it.