How to scale image to fit the container? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30 pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Adjusting and image Size to fit a div (bootstrap)How to make an image center (vertically & horizontally) inside a smaller divHow to horizontally center a <div>?Vertically align text next to an image?How do I give text or an image a transparent background using CSS?How to disable text selection highlighting?How to make a div 100% height of the browser window?How do I combine a background-image and CSS3 gradient on the same element?How do I auto-resize an image to fit a 'div' container?How can I transition height: 0; to height: auto; using CSS?How do CSS triangles work?Font scaling based on width of container

How to keep bees out of canned beverages?

In search of the origins of term censor, I hit a dead end stuck with the greek term, to censor, λογοκρίνω

A journey... into the MIND

How was Lagrange appointed professor of mathematics so early?

Could a cockatrice have parasitic embryos?

/bin/ls sorts differently than just ls

Why does Java have support for time zone offsets with seconds precision?

Suing a Police Officer Instead of the Police Department

Will I lose my paid in full property

Are these square matrices always diagonalisable?

Is there a way to fake a method response using Mock or Stubs?

What is the numbering system used for the DSN dishes?

Why did Europeans not widely domesticate foxes?

Will temporary Dex penalties prevent you from getting the benefits of the "Two Weapon Fighting" feat if your Dex score falls below the prerequisite?

Is it appropriate to mention a relatable company blog post when you're asked about the company?

Co-worker works way more than he should

What's parked in Mil Moscow helicopter plant?

Why do people think Winterfell crypts is the safest place for women, children & old people?

Israeli soda type drink

Does using the Inspiration rules for character defects encourage My Guy Syndrome?

Is Bran literally the world's memory?

What is ls Largest Number Formed by only moving two sticks in 508?

What do you call an IPA symbol that lacks a name (e.g. ɲ)?

What does the black goddess statue do and what is it?



How to scale image to fit the container?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30 pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Adjusting and image Size to fit a div (bootstrap)How to make an image center (vertically & horizontally) inside a smaller divHow to horizontally center a <div>?Vertically align text next to an image?How do I give text or an image a transparent background using CSS?How to disable text selection highlighting?How to make a div 100% height of the browser window?How do I combine a background-image and CSS3 gradient on the same element?How do I auto-resize an image to fit a 'div' container?How can I transition height: 0; to height: auto; using CSS?How do CSS triangles work?Font scaling based on width of container



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








21















I have an image list, I want images scaled into their containers which have same size.
like this:



ab



I created a jsfiddle



<div class="container">
<div class="row">
<div class="col-xs-3">
<a href="#" class="thumbnail">
<img src="http://exmoorpet.com/wp-content/uploads/2012/08/cat.png">
</a>
</div>
<div class="col-xs-3">
<a href="#" class="thumbnail">
<img src="http://www.nose2tail.co.uk/cat-matlock-derbyshire.jpg">
</a>
</div>
<div class="col-xs-3">
<a href="#" class="thumbnail">
<img src="http://www.us.onsior.com/images/3_1/cat-3_1-01.png">
</a>
</div>
<div class="col-xs-3">
<a href="#" class="thumbnail">
<img src="https://www.petfinder.com/wp-content/uploads/2012/11/155293403-cat-adoption-checklist-632x475-e1354290788940.jpg" >
</a>
</div>
</div>
</div>




How can I do that?
And in my example, I defined height: 100px;, this leads to not responsive, if I resize the browser, the div's height remain unchanged. If possible, I want this image list responsive.










share|improve this question
























  • This might help you.. jsfiddle.net/68b3g7pw/2

    – Shrinivas Pai
    Jun 2 '15 at 11:56












  • See also: stackoverflow.com/a/30252800/59087

    – Dave Jarvis
    Nov 27 '16 at 0:29


















21















I have an image list, I want images scaled into their containers which have same size.
like this:



ab



I created a jsfiddle



<div class="container">
<div class="row">
<div class="col-xs-3">
<a href="#" class="thumbnail">
<img src="http://exmoorpet.com/wp-content/uploads/2012/08/cat.png">
</a>
</div>
<div class="col-xs-3">
<a href="#" class="thumbnail">
<img src="http://www.nose2tail.co.uk/cat-matlock-derbyshire.jpg">
</a>
</div>
<div class="col-xs-3">
<a href="#" class="thumbnail">
<img src="http://www.us.onsior.com/images/3_1/cat-3_1-01.png">
</a>
</div>
<div class="col-xs-3">
<a href="#" class="thumbnail">
<img src="https://www.petfinder.com/wp-content/uploads/2012/11/155293403-cat-adoption-checklist-632x475-e1354290788940.jpg" >
</a>
</div>
</div>
</div>




How can I do that?
And in my example, I defined height: 100px;, this leads to not responsive, if I resize the browser, the div's height remain unchanged. If possible, I want this image list responsive.










share|improve this question
























  • This might help you.. jsfiddle.net/68b3g7pw/2

    – Shrinivas Pai
    Jun 2 '15 at 11:56












  • See also: stackoverflow.com/a/30252800/59087

    – Dave Jarvis
    Nov 27 '16 at 0:29














21












21








21


7






I have an image list, I want images scaled into their containers which have same size.
like this:



ab



I created a jsfiddle



<div class="container">
<div class="row">
<div class="col-xs-3">
<a href="#" class="thumbnail">
<img src="http://exmoorpet.com/wp-content/uploads/2012/08/cat.png">
</a>
</div>
<div class="col-xs-3">
<a href="#" class="thumbnail">
<img src="http://www.nose2tail.co.uk/cat-matlock-derbyshire.jpg">
</a>
</div>
<div class="col-xs-3">
<a href="#" class="thumbnail">
<img src="http://www.us.onsior.com/images/3_1/cat-3_1-01.png">
</a>
</div>
<div class="col-xs-3">
<a href="#" class="thumbnail">
<img src="https://www.petfinder.com/wp-content/uploads/2012/11/155293403-cat-adoption-checklist-632x475-e1354290788940.jpg" >
</a>
</div>
</div>
</div>




How can I do that?
And in my example, I defined height: 100px;, this leads to not responsive, if I resize the browser, the div's height remain unchanged. If possible, I want this image list responsive.










share|improve this question
















I have an image list, I want images scaled into their containers which have same size.
like this:



ab



I created a jsfiddle



<div class="container">
<div class="row">
<div class="col-xs-3">
<a href="#" class="thumbnail">
<img src="http://exmoorpet.com/wp-content/uploads/2012/08/cat.png">
</a>
</div>
<div class="col-xs-3">
<a href="#" class="thumbnail">
<img src="http://www.nose2tail.co.uk/cat-matlock-derbyshire.jpg">
</a>
</div>
<div class="col-xs-3">
<a href="#" class="thumbnail">
<img src="http://www.us.onsior.com/images/3_1/cat-3_1-01.png">
</a>
</div>
<div class="col-xs-3">
<a href="#" class="thumbnail">
<img src="https://www.petfinder.com/wp-content/uploads/2012/11/155293403-cat-adoption-checklist-632x475-e1354290788940.jpg" >
</a>
</div>
</div>
</div>




How can I do that?
And in my example, I defined height: 100px;, this leads to not responsive, if I resize the browser, the div's height remain unchanged. If possible, I want this image list responsive.







css twitter-bootstrap css3 twitter-bootstrap-3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 2 '15 at 12:03







Sato

















asked Jun 2 '15 at 11:52









SatoSato

2,93663368




2,93663368












  • This might help you.. jsfiddle.net/68b3g7pw/2

    – Shrinivas Pai
    Jun 2 '15 at 11:56












  • See also: stackoverflow.com/a/30252800/59087

    – Dave Jarvis
    Nov 27 '16 at 0:29


















  • This might help you.. jsfiddle.net/68b3g7pw/2

    – Shrinivas Pai
    Jun 2 '15 at 11:56












  • See also: stackoverflow.com/a/30252800/59087

    – Dave Jarvis
    Nov 27 '16 at 0:29

















This might help you.. jsfiddle.net/68b3g7pw/2

– Shrinivas Pai
Jun 2 '15 at 11:56






This might help you.. jsfiddle.net/68b3g7pw/2

– Shrinivas Pai
Jun 2 '15 at 11:56














See also: stackoverflow.com/a/30252800/59087

– Dave Jarvis
Nov 27 '16 at 0:29






See also: stackoverflow.com/a/30252800/59087

– Dave Jarvis
Nov 27 '16 at 0:29













8 Answers
8






active

oldest

votes


















32














Change the height and width to max-height and max-width. The image won't be any bigger than it's parent.



.thumbnail img 
max-height: 100%;
max-width: 100%;



Updated Fiddle






share|improve this answer























  • How to make img align center(horizontal and vertical)? And in my example, I defined height: 100px;, this leads to not responsive, if I resize the browser, the div's height remain unchanged.

    – Sato
    Jun 2 '15 at 11:59







  • 2





    You can use display: table-cell; with vertical-align: middle; jsfiddle.net/7gk6squL

    – Philip Dernovoy
    Jun 2 '15 at 12:09












  • This is the one answer (and I've looked at a dozen or so similar questions) that will actually do what I was looking for! No matter the size of the surrounding div, the image will keep its aspect ratio and shrink/grow the image to fit it to 100% of the most relevant side.

    – David Routen
    Jan 7 '16 at 21:34


















6














.thumbnail 
height: 100px;
display: table;


.thumbnail img
height: 100%;
width: 100%;
display: table-cell;
vertical-align: middle;






share|improve this answer
































    2














    In 2017 you can use flex. Additionally you will get the images centered in the thumbnail container: updated fiddle



    .thumbnail 
    height: 300px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border: solid 1px blue;


    .thumbnail img
    max-width: 100%;
    max-height: 100%;
    display: block;
    margin: 0 auto;
    border: solid 1px red;






    share|improve this answer






























      1














      This should help, at least for your example. There might be some cases in which this will not work. In that case you have to find a js solution.



      .thumbnail img 
      height: 100%;
      width: auto;






      share|improve this answer






























        0














        .thumbnail img 
        height: 100%;
        width: 100%;



        Use this.






        share|improve this answer






























          0














           .thumbnail 
          height: 100%;


          .thumbnail img
          max-height: 100%;
          max-width: 100%;
          border: 1px solid red;






          share|improve this answer






























            0














            (I'll add an answer although this is a old question. I had the same issue until I added the class thumbnail to the image link and looked a little bit deeper. No added css was necessary.)



            Maybe something is changed. In Bootstrap 3.3.7. there is this (non-minified css, line 5019):



            .thumbnail > img,
            .thumbnail a > img
            margin-left: auto;
            margin-right: auto;



            And this (non-minified css, line 1124):



            .img-responsive,
            .thumbnail > img,
            .thumbnail a > img,
            .carousel-inner > .item > img,
            .carousel-inner > .item > a > img
            display: block;
            max-width: 100%;
            height: auto;



            So everything should work right out of the box if you have added the class thumbnail to the image link. (You need to remove both of those and things will break.) And it works with or without the added css:



            .thumbnail img 
            max-height: 100%;
            max-width: 100%;



            The added css overrides Bootstraps styles, at least for me since the added style is included after the Bootstraps own styles. (But it is redundant.)






            share|improve this answer






























              0














              <img src="..." class="img-fluid" alt="Responsive image">





              share|improve this answer























              • Please consider adding a description of your code so we know what it does and why.

                – Pikachu the Purple Wizard
                Mar 9 at 5:20











              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30595321%2fhow-to-scale-image-to-fit-the-container%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              8 Answers
              8






              active

              oldest

              votes








              8 Answers
              8






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              32














              Change the height and width to max-height and max-width. The image won't be any bigger than it's parent.



              .thumbnail img 
              max-height: 100%;
              max-width: 100%;



              Updated Fiddle






              share|improve this answer























              • How to make img align center(horizontal and vertical)? And in my example, I defined height: 100px;, this leads to not responsive, if I resize the browser, the div's height remain unchanged.

                – Sato
                Jun 2 '15 at 11:59







              • 2





                You can use display: table-cell; with vertical-align: middle; jsfiddle.net/7gk6squL

                – Philip Dernovoy
                Jun 2 '15 at 12:09












              • This is the one answer (and I've looked at a dozen or so similar questions) that will actually do what I was looking for! No matter the size of the surrounding div, the image will keep its aspect ratio and shrink/grow the image to fit it to 100% of the most relevant side.

                – David Routen
                Jan 7 '16 at 21:34















              32














              Change the height and width to max-height and max-width. The image won't be any bigger than it's parent.



              .thumbnail img 
              max-height: 100%;
              max-width: 100%;



              Updated Fiddle






              share|improve this answer























              • How to make img align center(horizontal and vertical)? And in my example, I defined height: 100px;, this leads to not responsive, if I resize the browser, the div's height remain unchanged.

                – Sato
                Jun 2 '15 at 11:59







              • 2





                You can use display: table-cell; with vertical-align: middle; jsfiddle.net/7gk6squL

                – Philip Dernovoy
                Jun 2 '15 at 12:09












              • This is the one answer (and I've looked at a dozen or so similar questions) that will actually do what I was looking for! No matter the size of the surrounding div, the image will keep its aspect ratio and shrink/grow the image to fit it to 100% of the most relevant side.

                – David Routen
                Jan 7 '16 at 21:34













              32












              32








              32







              Change the height and width to max-height and max-width. The image won't be any bigger than it's parent.



              .thumbnail img 
              max-height: 100%;
              max-width: 100%;



              Updated Fiddle






              share|improve this answer













              Change the height and width to max-height and max-width. The image won't be any bigger than it's parent.



              .thumbnail img 
              max-height: 100%;
              max-width: 100%;



              Updated Fiddle







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jun 2 '15 at 11:55









              LinkinTEDLinkinTED

              14.9k31846




              14.9k31846












              • How to make img align center(horizontal and vertical)? And in my example, I defined height: 100px;, this leads to not responsive, if I resize the browser, the div's height remain unchanged.

                – Sato
                Jun 2 '15 at 11:59







              • 2





                You can use display: table-cell; with vertical-align: middle; jsfiddle.net/7gk6squL

                – Philip Dernovoy
                Jun 2 '15 at 12:09












              • This is the one answer (and I've looked at a dozen or so similar questions) that will actually do what I was looking for! No matter the size of the surrounding div, the image will keep its aspect ratio and shrink/grow the image to fit it to 100% of the most relevant side.

                – David Routen
                Jan 7 '16 at 21:34

















              • How to make img align center(horizontal and vertical)? And in my example, I defined height: 100px;, this leads to not responsive, if I resize the browser, the div's height remain unchanged.

                – Sato
                Jun 2 '15 at 11:59







              • 2





                You can use display: table-cell; with vertical-align: middle; jsfiddle.net/7gk6squL

                – Philip Dernovoy
                Jun 2 '15 at 12:09












              • This is the one answer (and I've looked at a dozen or so similar questions) that will actually do what I was looking for! No matter the size of the surrounding div, the image will keep its aspect ratio and shrink/grow the image to fit it to 100% of the most relevant side.

                – David Routen
                Jan 7 '16 at 21:34
















              How to make img align center(horizontal and vertical)? And in my example, I defined height: 100px;, this leads to not responsive, if I resize the browser, the div's height remain unchanged.

              – Sato
              Jun 2 '15 at 11:59






              How to make img align center(horizontal and vertical)? And in my example, I defined height: 100px;, this leads to not responsive, if I resize the browser, the div's height remain unchanged.

              – Sato
              Jun 2 '15 at 11:59





              2




              2





              You can use display: table-cell; with vertical-align: middle; jsfiddle.net/7gk6squL

              – Philip Dernovoy
              Jun 2 '15 at 12:09






              You can use display: table-cell; with vertical-align: middle; jsfiddle.net/7gk6squL

              – Philip Dernovoy
              Jun 2 '15 at 12:09














              This is the one answer (and I've looked at a dozen or so similar questions) that will actually do what I was looking for! No matter the size of the surrounding div, the image will keep its aspect ratio and shrink/grow the image to fit it to 100% of the most relevant side.

              – David Routen
              Jan 7 '16 at 21:34





              This is the one answer (and I've looked at a dozen or so similar questions) that will actually do what I was looking for! No matter the size of the surrounding div, the image will keep its aspect ratio and shrink/grow the image to fit it to 100% of the most relevant side.

              – David Routen
              Jan 7 '16 at 21:34













              6














              .thumbnail 
              height: 100px;
              display: table;


              .thumbnail img
              height: 100%;
              width: 100%;
              display: table-cell;
              vertical-align: middle;






              share|improve this answer





























                6














                .thumbnail 
                height: 100px;
                display: table;


                .thumbnail img
                height: 100%;
                width: 100%;
                display: table-cell;
                vertical-align: middle;






                share|improve this answer



























                  6












                  6








                  6







                  .thumbnail 
                  height: 100px;
                  display: table;


                  .thumbnail img
                  height: 100%;
                  width: 100%;
                  display: table-cell;
                  vertical-align: middle;






                  share|improve this answer















                  .thumbnail 
                  height: 100px;
                  display: table;


                  .thumbnail img
                  height: 100%;
                  width: 100%;
                  display: table-cell;
                  vertical-align: middle;







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jun 2 '15 at 12:15

























                  answered Jun 2 '15 at 11:58









                  Coding EnthusiastCoding Enthusiast

                  3,19911637




                  3,19911637





















                      2














                      In 2017 you can use flex. Additionally you will get the images centered in the thumbnail container: updated fiddle



                      .thumbnail 
                      height: 300px;
                      display: flex;
                      flex-direction: column;
                      justify-content: center;
                      align-items: center;
                      border: solid 1px blue;


                      .thumbnail img
                      max-width: 100%;
                      max-height: 100%;
                      display: block;
                      margin: 0 auto;
                      border: solid 1px red;






                      share|improve this answer



























                        2














                        In 2017 you can use flex. Additionally you will get the images centered in the thumbnail container: updated fiddle



                        .thumbnail 
                        height: 300px;
                        display: flex;
                        flex-direction: column;
                        justify-content: center;
                        align-items: center;
                        border: solid 1px blue;


                        .thumbnail img
                        max-width: 100%;
                        max-height: 100%;
                        display: block;
                        margin: 0 auto;
                        border: solid 1px red;






                        share|improve this answer

























                          2












                          2








                          2







                          In 2017 you can use flex. Additionally you will get the images centered in the thumbnail container: updated fiddle



                          .thumbnail 
                          height: 300px;
                          display: flex;
                          flex-direction: column;
                          justify-content: center;
                          align-items: center;
                          border: solid 1px blue;


                          .thumbnail img
                          max-width: 100%;
                          max-height: 100%;
                          display: block;
                          margin: 0 auto;
                          border: solid 1px red;






                          share|improve this answer













                          In 2017 you can use flex. Additionally you will get the images centered in the thumbnail container: updated fiddle



                          .thumbnail 
                          height: 300px;
                          display: flex;
                          flex-direction: column;
                          justify-content: center;
                          align-items: center;
                          border: solid 1px blue;


                          .thumbnail img
                          max-width: 100%;
                          max-height: 100%;
                          display: block;
                          margin: 0 auto;
                          border: solid 1px red;







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Oct 3 '17 at 7:08









                          raisercostinraisercostin

                          5,25034456




                          5,25034456





















                              1














                              This should help, at least for your example. There might be some cases in which this will not work. In that case you have to find a js solution.



                              .thumbnail img 
                              height: 100%;
                              width: auto;






                              share|improve this answer



























                                1














                                This should help, at least for your example. There might be some cases in which this will not work. In that case you have to find a js solution.



                                .thumbnail img 
                                height: 100%;
                                width: auto;






                                share|improve this answer

























                                  1












                                  1








                                  1







                                  This should help, at least for your example. There might be some cases in which this will not work. In that case you have to find a js solution.



                                  .thumbnail img 
                                  height: 100%;
                                  width: auto;






                                  share|improve this answer













                                  This should help, at least for your example. There might be some cases in which this will not work. In that case you have to find a js solution.



                                  .thumbnail img 
                                  height: 100%;
                                  width: auto;







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered Jun 2 '15 at 11:58









                                  m4lt3m4lt3

                                  19510




                                  19510





















                                      0














                                      .thumbnail img 
                                      height: 100%;
                                      width: 100%;



                                      Use this.






                                      share|improve this answer



























                                        0














                                        .thumbnail img 
                                        height: 100%;
                                        width: 100%;



                                        Use this.






                                        share|improve this answer

























                                          0












                                          0








                                          0







                                          .thumbnail img 
                                          height: 100%;
                                          width: 100%;



                                          Use this.






                                          share|improve this answer













                                          .thumbnail img 
                                          height: 100%;
                                          width: 100%;



                                          Use this.







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Jun 2 '15 at 12:01









                                          Danish KhanDanish Khan

                                          10318




                                          10318





















                                              0














                                               .thumbnail 
                                              height: 100%;


                                              .thumbnail img
                                              max-height: 100%;
                                              max-width: 100%;
                                              border: 1px solid red;






                                              share|improve this answer



























                                                0














                                                 .thumbnail 
                                                height: 100%;


                                                .thumbnail img
                                                max-height: 100%;
                                                max-width: 100%;
                                                border: 1px solid red;






                                                share|improve this answer

























                                                  0












                                                  0








                                                  0







                                                   .thumbnail 
                                                  height: 100%;


                                                  .thumbnail img
                                                  max-height: 100%;
                                                  max-width: 100%;
                                                  border: 1px solid red;






                                                  share|improve this answer













                                                   .thumbnail 
                                                  height: 100%;


                                                  .thumbnail img
                                                  max-height: 100%;
                                                  max-width: 100%;
                                                  border: 1px solid red;







                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered Jun 3 '15 at 16:38









                                                  Mr_vasuMr_vasu

                                                  8319




                                                  8319





















                                                      0














                                                      (I'll add an answer although this is a old question. I had the same issue until I added the class thumbnail to the image link and looked a little bit deeper. No added css was necessary.)



                                                      Maybe something is changed. In Bootstrap 3.3.7. there is this (non-minified css, line 5019):



                                                      .thumbnail > img,
                                                      .thumbnail a > img
                                                      margin-left: auto;
                                                      margin-right: auto;



                                                      And this (non-minified css, line 1124):



                                                      .img-responsive,
                                                      .thumbnail > img,
                                                      .thumbnail a > img,
                                                      .carousel-inner > .item > img,
                                                      .carousel-inner > .item > a > img
                                                      display: block;
                                                      max-width: 100%;
                                                      height: auto;



                                                      So everything should work right out of the box if you have added the class thumbnail to the image link. (You need to remove both of those and things will break.) And it works with or without the added css:



                                                      .thumbnail img 
                                                      max-height: 100%;
                                                      max-width: 100%;



                                                      The added css overrides Bootstraps styles, at least for me since the added style is included after the Bootstraps own styles. (But it is redundant.)






                                                      share|improve this answer



























                                                        0














                                                        (I'll add an answer although this is a old question. I had the same issue until I added the class thumbnail to the image link and looked a little bit deeper. No added css was necessary.)



                                                        Maybe something is changed. In Bootstrap 3.3.7. there is this (non-minified css, line 5019):



                                                        .thumbnail > img,
                                                        .thumbnail a > img
                                                        margin-left: auto;
                                                        margin-right: auto;



                                                        And this (non-minified css, line 1124):



                                                        .img-responsive,
                                                        .thumbnail > img,
                                                        .thumbnail a > img,
                                                        .carousel-inner > .item > img,
                                                        .carousel-inner > .item > a > img
                                                        display: block;
                                                        max-width: 100%;
                                                        height: auto;



                                                        So everything should work right out of the box if you have added the class thumbnail to the image link. (You need to remove both of those and things will break.) And it works with or without the added css:



                                                        .thumbnail img 
                                                        max-height: 100%;
                                                        max-width: 100%;



                                                        The added css overrides Bootstraps styles, at least for me since the added style is included after the Bootstraps own styles. (But it is redundant.)






                                                        share|improve this answer

























                                                          0












                                                          0








                                                          0







                                                          (I'll add an answer although this is a old question. I had the same issue until I added the class thumbnail to the image link and looked a little bit deeper. No added css was necessary.)



                                                          Maybe something is changed. In Bootstrap 3.3.7. there is this (non-minified css, line 5019):



                                                          .thumbnail > img,
                                                          .thumbnail a > img
                                                          margin-left: auto;
                                                          margin-right: auto;



                                                          And this (non-minified css, line 1124):



                                                          .img-responsive,
                                                          .thumbnail > img,
                                                          .thumbnail a > img,
                                                          .carousel-inner > .item > img,
                                                          .carousel-inner > .item > a > img
                                                          display: block;
                                                          max-width: 100%;
                                                          height: auto;



                                                          So everything should work right out of the box if you have added the class thumbnail to the image link. (You need to remove both of those and things will break.) And it works with or without the added css:



                                                          .thumbnail img 
                                                          max-height: 100%;
                                                          max-width: 100%;



                                                          The added css overrides Bootstraps styles, at least for me since the added style is included after the Bootstraps own styles. (But it is redundant.)






                                                          share|improve this answer













                                                          (I'll add an answer although this is a old question. I had the same issue until I added the class thumbnail to the image link and looked a little bit deeper. No added css was necessary.)



                                                          Maybe something is changed. In Bootstrap 3.3.7. there is this (non-minified css, line 5019):



                                                          .thumbnail > img,
                                                          .thumbnail a > img
                                                          margin-left: auto;
                                                          margin-right: auto;



                                                          And this (non-minified css, line 1124):



                                                          .img-responsive,
                                                          .thumbnail > img,
                                                          .thumbnail a > img,
                                                          .carousel-inner > .item > img,
                                                          .carousel-inner > .item > a > img
                                                          display: block;
                                                          max-width: 100%;
                                                          height: auto;



                                                          So everything should work right out of the box if you have added the class thumbnail to the image link. (You need to remove both of those and things will break.) And it works with or without the added css:



                                                          .thumbnail img 
                                                          max-height: 100%;
                                                          max-width: 100%;



                                                          The added css overrides Bootstraps styles, at least for me since the added style is included after the Bootstraps own styles. (But it is redundant.)







                                                          share|improve this answer












                                                          share|improve this answer



                                                          share|improve this answer










                                                          answered Jun 13 '17 at 6:39









                                                          ZZ-bbZZ-bb

                                                          2,00612032




                                                          2,00612032





















                                                              0














                                                              <img src="..." class="img-fluid" alt="Responsive image">





                                                              share|improve this answer























                                                              • Please consider adding a description of your code so we know what it does and why.

                                                                – Pikachu the Purple Wizard
                                                                Mar 9 at 5:20















                                                              0














                                                              <img src="..." class="img-fluid" alt="Responsive image">





                                                              share|improve this answer























                                                              • Please consider adding a description of your code so we know what it does and why.

                                                                – Pikachu the Purple Wizard
                                                                Mar 9 at 5:20













                                                              0












                                                              0








                                                              0







                                                              <img src="..." class="img-fluid" alt="Responsive image">





                                                              share|improve this answer













                                                              <img src="..." class="img-fluid" alt="Responsive image">






                                                              share|improve this answer












                                                              share|improve this answer



                                                              share|improve this answer










                                                              answered Mar 9 at 4:44









                                                              Embedded MusicEmbedded Music

                                                              196




                                                              196












                                                              • Please consider adding a description of your code so we know what it does and why.

                                                                – Pikachu the Purple Wizard
                                                                Mar 9 at 5:20

















                                                              • Please consider adding a description of your code so we know what it does and why.

                                                                – Pikachu the Purple Wizard
                                                                Mar 9 at 5:20
















                                                              Please consider adding a description of your code so we know what it does and why.

                                                              – Pikachu the Purple Wizard
                                                              Mar 9 at 5:20





                                                              Please consider adding a description of your code so we know what it does and why.

                                                              – Pikachu the Purple Wizard
                                                              Mar 9 at 5:20

















                                                              draft saved

                                                              draft discarded
















































                                                              Thanks for contributing an answer to Stack Overflow!


                                                              • Please be sure to answer the question. Provide details and share your research!

                                                              But avoid


                                                              • Asking for help, clarification, or responding to other answers.

                                                              • Making statements based on opinion; back them up with references or personal experience.

                                                              To learn more, see our tips on writing great answers.




                                                              draft saved


                                                              draft discarded














                                                              StackExchange.ready(
                                                              function ()
                                                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30595321%2fhow-to-scale-image-to-fit-the-container%23new-answer', 'question_page');

                                                              );

                                                              Post as a guest















                                                              Required, but never shown





















































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown

































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown







                                                              Popular posts from this blog

                                                              Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                                                              Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                                                              Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved