Can I limit the width of text inside of a <p>?

Viewed 53
1 Answers

You can solve this using CSS grid:

.container {
  margin:0 50px;
  border:1px solid;
}
.container >p {
  display:grid;
  grid-template-columns:1fr minmax(0,20rem) 1fr;
}

/* this pseudo element will take the first column and force the text to be on the middle one */
p::before {
  content:"";
}
/**/

p > img {
  grid-column:1/span 3; /* the image should take all the 3 columns (full width) */
}

img {
 max-width:100%;
}
<div class="container">
<p>Lorem ipsum dolor amet tousled viral art party blue bottle single-origin coffee cardigan, selvage man braid helvetica. Banh mi taxidermy meditation microdosing. Selvage cornhole YOLO, small batch vexillologist raclette VHS prism sustainable 8-bit ugh semiotics letterpress disrupt pop-up. Celiac shabby chic ugh, jianbing whatever kitsch tattooed edison bulb kogi irony etsy.</p>
<p><img src="https://images.unsplash.com/photo-1580792214064-6102bf1948d5?ixlib=rb-1.2.1&amp;ixid=eyJhcHBfaWQiOjEyMDd9&amp;auto=format&amp;fit=crop&amp;w=2167&amp;q=80" alt="image"></p>
<p>Lorem ipsum dolor amet tousled viral art party blue bottle single-origin coffee cardigan, selvage man braid helvetica. Banh mi taxidermy meditation microdosing. Selvage cornhole YOLO, small batch vexillologist raclette VHS prism sustainable 8-bit ugh semiotics letterpress disrupt pop-up. Celiac shabby chic ugh, jianbing whatever kitsch tattooed edison bulb kogi irony etsy.</p>
</div>

Related