Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stretch image to fit full container width bootstrap

I have an image that's 1300px wide, using bootstrap I want this image to fill the full width of my container which is set to 1300px. I create a row, give it a full 12 columns and then add in the image with a class of image responsive. With this set up I get the output below.

enter image description here

I want my image to stretch all the way along to where my image is in my content, here is my code.

  <div class="row">     <div class="container">       <div class="col-md-12">         <img src="<?php bloginfo('template_directory'); ?>/assets/img/homeBanner.jpg" alt="placeholder 960" class="img-responsive"/>       </div>     </div>   </div> 

The image is set to width 100% so not sure why it isn't filling the container.

like image 344
pocockn Avatar asked Apr 29 '16 08:04

pocockn


People also ask

How do I make an image fit a container in Bootstrap?

“bootstrap 4 image size to fit” Code Answer's you have to set the width of image to 100%, for that you can use Bootstrap class "w-100". keep in mind that "container-fluid" and "col-12" class sets left and right padding to 15px and "row" class sets left and right margin to "-15px" by default. make sure to set them to 0.

How do I create a 100% screen width div inside a container in Bootstrap?

If you want to make it stretch 100% to the screen either you make the "full-width-div" position fixed or use the "container-fluid" class instead of "container".


1 Answers

In bootstrap 4.1, the w-100 class is required along with img-fluid for images smaller than the page to be stretched:

<div class="container">   <div class="row">     <img class='img-fluid w-100' src="#" alt="" />   </div> </div> 

see closed issue: https://github.com/twbs/bootstrap/issues/20830

(As of 2018-04-20, the documentation is wrong: https://getbootstrap.com/docs/4.1/content/images/ says that img-fluid applies max-width: 100%; height: auto;" but img-fluid does not resolve the issue, and neither does manually adding those style attributes with or without bootstrap classes on the img tag.)

like image 130
Poikilos Avatar answered Sep 21 '22 13:09

Poikilos