skip to Main Content

I want to show an image with text next to the image. 3 images in a row. The following code example will wrap the text but I need it all to fit the width of the container.

I have seen that this can be achieved using a unordered list as well but I have not been able to figure that out either.

.banner-row {
  display: flex;
}
.banner-column {
  flex: 33.33%;
  padding: 15px;
}
.banner-container {
  display: flex;
  align-items: center;
  justify-content: center
}

banner-img {
  max-width: 100%;
  max-height:100%;
}

.banner-text {
  font-size: 20px;
  padding-left: 20px;
}
/* Clear floats after the columns */
.row:after {
  content: "";
  display: table;
  clear: both;
}

I then have the html code as follows:

<div class="banner-row">
  <div class="banner-column">
    <img src="https://cdn.shopify.com/s/files/1/0778/0778/0187/files/reduces-headaches-yellow.png" alt="Snow" style="width:33%"><div>Reduces Headaches</div>
  </div>
  <div class="banner-column">
    <img src="https://cdn.shopify.com/s/files/1/0778/0778/0187/files/relieves-neck-pain-yellow.png" alt="Forest" style="width:33%"><div>Relieves Neck Pain</div>
  </div>
  <div class="banner-column">
    <img src="https://cdn.shopify.com/s/files/1/0778/0778/0187/files/wake-up-refreshed-yello.png" alt="Mountains" style="width:33%"><div>Improves Sleep</div>
  </div>
</div>```

[![Image shows the text wrapping][1]][1]


  [1]: https://i.stack.imgur.com/wVYjL.png

3

Answers


  1. Just add display: flex in banner-column it should work

    .banner-column {
      flex: 33.33%;
      padding: 15px;
      display: flex;
    }
    

    to make them align center

        .banner-column {
              flex: 33.33%;
              padding: 15px;
              display: flex;
    align-items: center;
            }
    
    Login or Signup to reply.
  2. .banner-column {
      flex: 33.33%;
      display : flex;
      justify-content : center;
      align-items: center;
      padding: 15px;
    }
    
    Login or Signup to reply.
  3. Your banner text div elements had no classes in them. I added some code to style the body just to make it easier to see. I hope this code produces the results you want.

    /*Copy paste in .html file and run it.*/
    <style>
        body {
            margin: 0;
            padding: 0;
            background: rgb(10, 2, 20);
            color: white;
            display: grid;
            justify-content: center; /*remove if you don't want a centered layout*/
            
        }
    
        .banner-row {
            display: flex;
           
        }
        .banner-column {
            display: flex;
            padding: 15px;
            
        }
        .banner-container {
            display: flex;
            align-items: center;
            justify-content: center
        }
    
        .banner-img {
            width: 33%;
        }
    
        .banner-text {
            font-size: 20px;
            padding-left: 20px;
        }
        /* Clear floats after the columns */
        .row:after {
            content: "";
            display: table;
            clear: both;
        }
    </style>
    
    
    
    
    <div class="banner-row">
        <div class="banner-column">
          <img src="https://cdn.shopify.com/s/files/1/0778/0778/0187/files/reduces-headaches-yellow.png" alt="Snow" class="banner-img"/>
          <div class="banner-text">Reduces Headaches</div>
        </div>
        <div class="banner-column">
          <img src="https://cdn.shopify.com/s/files/1/0778/0778/0187/files/relieves-neck-pain-yellow.png" alt="Forest" class="banner-img" />
          <div class="banner-text">Relieves Neck Pain</div>
        </div>
        <div class="banner-column">
          <img src="https://cdn.shopify.com/s/files/1/0778/0778/0187/files/wake-up-refreshed-yello.png" alt="Mountains" class="banner-img" />
          <div class="banner-text">Improves Sleep</div>
        </div>
      </div>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search