Solution 1 :

flex-wrap:wrap; On the container

flex:1 0 150px; On the text, This translates to

flex-grow:1;      // grow to fill remaining space
flex-shrink:0;    // don't ever shrink
flex-basis:150px; // have a minimum width of 150px

  1. The text should stay in it’s column but wrap or expand in it’s column changes width

flex-grow:1; will make the text expand to fill the remaining space in it’s column and wrap if the column changes width.

  1. when the right column is under 150px I’d like the text to drop below the image

Since the text have a minimum width of 150px we know that it needs at least 150px to stay next to the image if there’s isn’t enough space it will drop below the image thanks to flex-wrap:wrap; on the parent.

  1. and use 100% of the outer container

Again flex-grow:1; will make the text grow to fill the remaining space.

.container {
  background-color: yellow;
  max-width: 300px;
  display: flex;
  flex-wrap: wrap;
}

.container>div {
  flex: 1 0 150px;
}


/* Not needed */

.container {
  margin: 10px auto;
  overflow: auto;
  resize: horizontal;
}

p {
  display: table;
  margin: auto;
}
<div class="container">
  <img src="https://via.placeholder.com/100">
  <div>this is some text text text this is some text text text this is some text text text</div>
</div>
<p>The text column isn't below 150px so it stays</p>
<div class="container">
  <img src="https://via.placeholder.com/150">
  <div>this is some text text text this is some text text text this is some text text text</div>
</div>
<p>text column is below 150px so it drops below the img</p>
<div class="container">
  <img src="https://via.placeholder.com/250">
  <div>this is some text text text this is some text text text this is some text text text</div>
</div>

Problem :

I’ve tried a bunch of stuff and can’t seem to format this:

I need an outer container that has a max-width of 300px which holds 2 columns of data. The left side is an image (it’s width can vary). The right column is text. The text should stay in it’s column but wrap or expand if it’s column changes width(eg when there’s a wider image or user shrinks the screen). And when the right column is under 150px I’d like the text to drop below the image and use 100% of the outer container( so there would be 2 rows of data instead of 2 columns.

For example:

enter image description here

or

enter image description here

If the image isn’t present I’d like the text to simply use 100 percent of the outer container. I’d like to not include javascript if possible. Here’s what I’ve tried.

.container {
  background-color: yellow;
  max-width:300px;
}

.container .item {
  display: inline-block;
  border: 1px solid black;
}
<!DOCTYPE html>
<html>
<head>
</style>
</head>
<body>


<div class="container">
  <div class="item">my image</div>
  <div class="item">this is some text text text</div>
</div>

</body>
</html>

^^ Notice that when you shrink the screen the text doesn’t wrap at all in it’s column but instead it snaps the entire text block below the image. I’d like it to wrap in it’s own column and then snap below only when it’s width is below 150px. Is this possible? I hope I’ve contained enough information.

Comments

Comment posted by RayLoveless

Why the down vote? I’m sincerely looking for help with this?

Comment posted by RayLoveless

Great answer!! Thanks for taking the time to look at this. Such a simple solution. I need to get better at using flexbox. This helps alot. I wish I could award you a bounty but it makes me wait 2 days before accepting an answer to do so.

Comment posted by Rainbow

@RayLoveless I’m just glad i can help 😀

By