Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Issue with images in card groups on BootStrap.

Having issues with the images not being the same size in a card group. See my code below:

  <h1 id="cakes" class="display-4 text-center my-5 text-muted">My Cakes</h1>
  <div class="row mx-auto">
    <div class="card-group">
    <div class="card" style="width: 20rem;">
      <img class="card-img-top img-fluid" src="img/cake1.jpg" alt="Card image cap">
      <div class="card-block">
        <h4 class="card-title">Awesome cake</h4>
        <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
        <a href="#" class="btn btn-primary">Learn More</a>
      </div>
    </div>


    <div class="card" style="width: 20rem;">
      <img class="card-img-top img-fluid" src="img/cake2.jpg" alt="Card image cap">
      <div class="card-block">
        <h4 class="card-title">Awesome cake</h4>
        <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
        <a href="#" class="btn btn-primary">Learn More</a>
      </div>
    </div>

    <div class="card" style="width: 20rem;">
      <img class="card-img-top img-fluid" src="img/cake3.jpg" alt="Card image cap">
      <div class="card-block">
        <h4 class="card-title">Awesome cake</h4>
        <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
        <a href="#" class="btn btn-primary">Learn More</a>
      </div>
    </div>
    </div>
  </div>

Cleaned up your question a bit to format the HTML code block. Be sure to check out the Markdown Cheatsheet below the editor for more info!

1 Answer

You'll likely want to define (at least) the width of the images in the cards to make sure the CSS forces them to the same size (rather than depending on the dimensions of the JPEGs themselves). For card layouts, I find the easiest solution is to apply the following attributes to images:

display: block;
width: 100%;