Combining float and padding in CSS
Let's put the image above the paragraphs again, leaving them with the left padding. In this case, padding will only move the text that is adjacent to the left of the parent div, and not to our image:
<div>
<img src="img.png" alt="">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elitorire.
</p>
<p>
some long text
</p>
</div>
div {
width: 400px;
border: 1px solid red;
text-align: justify;
}
p {
margin-left: 30px;
padding-left: 30px;
border: 1px solid green;
}
img {
float: left;
opacity: 0.5;
}
:
Now let's put the picture in the first paragraph - it will move to the right along with the text of the paragraphs:
<div>
<p>
<img src="img.png" alt="">
Lorem ipsum dolor sit amet, consectetur adipiscing elitorire.
</p>
<p>
some long text
</p>
</div>
div {
width: 400px;
border: 1px solid red;
text-align: justify;
}
p {
margin-left: 30px;
padding-left: 30px;
border: 1px solid green;
}
img {
float: left;
opacity: 0.5;
}
: