Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter Bootstrap Auto Resize Picture to take up entire column

I'm using bootstrap and I have a row with two columns. One of the columns has one picture in it which should take up all of the space in the column. The column on the right has three rows in it with 2 pictures in each row. But so far I can't get the image on the left to resize correctly and just stays at a small fixed size. Here is the code.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap 101 Template</title>

    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/custom2.css" rel="stylesheet">

  </head>
  <body>

        <div class="col-md-12">

            <div class="row">
                <h2>Recent</h2>

                <div id="myGallery" class="col-md-7">
                    <a href="#"><img src="images/9-12,13 40.jpg" class="img-responsive"></a>
                </div>

                 <div class="col-md-5">
                    <div class="row">
                        <div class="col-md-6"><a href="#"><img src="images/9-12,13 40.jpg" class="img-responsive"></a></div>
                        <div class="col-md-6"><a href="#"><img src="images/9-12,13 40.jpg" class="img-responsive"></a></div>
                        </div>
                    <br>
                    <div class="row">
                        <div class="col-md-6"><a href="#"><img src="images/9-12,13 40.jpg" class="img-responsive"></a></div>
                        <div class="col-md-6"><a href="#"><img src="images/9-12,13 40.jpg" class="img-responsive"></a></div>
                        </div>
                    <br>
                    <div class="row">
                        <div class="col-md-6"><a href="#"><img src="images/9-12,13 40.jpg" class="img-responsive"></a></div>
                        <div class="col-md-6"><a href="#"><img src="images/9-12,13 40.jpg" class="img-responsive"></a></div>
                        </div>
                 </div>
            </div>  
        </div>


    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>

  </body>
</html>

and my css

img
{
 max-width:auto; 
 max-height:auto;   
}

I have been able to set a minimum width for it like

.myClass img{
    min-width: 775px; 
}

but if the browser window size changes then it stays the same size and doesn't look as good.

Here is what it currently looks like before

And it should look like this after

How do I go about fixing this in the css? Thanks for the help!

like image 797
Andrew Avatar asked Jul 28 '14 13:07

Andrew


People also ask

How do I autofit an image in a div?

To auto-resize an image or a video to fit in a div container use object-fit property. It is used to specify how an image or video fits in the container. object-fit property: This property is used to specify how an image or video resize and fit the container.

How do I resize an image automatically?

Answer: Use the CSS max-width Property You can simply use the CSS max-width property to auto-resize a large image so that it can fit into a smaller width <div> container while maintaining its aspect ratio.

How do I change the size of an image in Bootstrap?

how to stretch image in size using bootstrap. 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.

Which class will you use to create a responsive image that changes its width based on the browser width?

Create responsive images by adding an . img-responsive class to the <img> tag. The image will then scale nicely to the parent element.


Video Answer


2 Answers

You should just set the image to have a width of 100%. That make the element take 100% of the width of the container it is inside:

img {
    width: 100%;
}
like image 72
DavidG Avatar answered Nov 02 '22 11:11

DavidG


Use Boostrap's img-responsive class.

like image 38
Daniel Apt Avatar answered Nov 02 '22 11:11

Daniel Apt