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

How do I get an image to fit the bootstrap carousel, and also be responsive?

I am using the twitter bootstrap carousel to scroll through three images. The only problem is that I cannot get the images to fill the corresponding divs that they sit within. Any ideas?

<div class="carousel-inner">

<div class="item active">      
    <img src="images/product_1.jpg" alt="First Product">                        
</div>

<div class="item">
  <img src="images/product_2.jpg" alt="Second Product">
</div>

<div class="item">
  <img src="images/product_3.jpg" alt="Third Product">
</div>              

</div> </div> <a class="left carousel-control" href="#myCarousel" data-slide="prev"> <span class="icon-prev"> </span> </a> <a class="right carousel-control" href="#myCarousel" data-slide="next"> <span class="icon-next"> </span> </a>

</div>

3 Answers

In this case It's a matter of css rules. Getting your html alone doesn't help much. Have you tried to use on these images the property max-width: 100% ? This way the image fills 100% of its container's width.

However, I haven't used boostrap for a while, but I had in mind images inside the carousel were automatically responsive...

Hi Geoffrey,

Yea I thought I'd show my HTML as all the CSS styles being applied are from the default bootstrap CSS file. I'm aware I'll have to change the CSS and have tried changing the max width to 100% and the height to auto but still have had no luck in getting the image to fill the carousel div.

Thanks

Simon

In your main css try: Img {background: cover;}

Or whatever is the selectors name that contains your image . I think in yours is "item"

Hope This helps