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;
I have an image list, I want images scaled into their containers which have same size.
like this:
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
add a comment |
I have an image list, I want images scaled into their containers which have same size.
like this:
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
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
add a comment |
I have an image list, I want images scaled into their containers which have same size.
like this:
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
I have an image list, I want images scaled into their containers which have same size.
like this:
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
css twitter-bootstrap css3 twitter-bootstrap-3
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
add a comment |
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
add a comment |
8 Answers
8
active
oldest
votes
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
How to make img align center(horizontal and vertical)? And in my example, I definedheight: 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 usedisplay: table-cell;
withvertical-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
add a comment |
.thumbnail
height: 100px;
display: table;
.thumbnail img
height: 100%;
width: 100%;
display: table-cell;
vertical-align: middle;
add a comment |
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;
add a comment |
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;
add a comment |
.thumbnail img
height: 100%;
width: 100%;
Use this.
add a comment |
.thumbnail
height: 100%;
.thumbnail img
max-height: 100%;
max-width: 100%;
border: 1px solid red;
add a comment |
(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.)
add a comment |
<img src="..." class="img-fluid" alt="Responsive image">
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
How to make img align center(horizontal and vertical)? And in my example, I definedheight: 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 usedisplay: table-cell;
withvertical-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
add a comment |
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
How to make img align center(horizontal and vertical)? And in my example, I definedheight: 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 usedisplay: table-cell;
withvertical-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
add a comment |
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
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
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 definedheight: 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 usedisplay: table-cell;
withvertical-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
add a comment |
How to make img align center(horizontal and vertical)? And in my example, I definedheight: 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 usedisplay: table-cell;
withvertical-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
add a comment |
.thumbnail
height: 100px;
display: table;
.thumbnail img
height: 100%;
width: 100%;
display: table-cell;
vertical-align: middle;
add a comment |
.thumbnail
height: 100px;
display: table;
.thumbnail img
height: 100%;
width: 100%;
display: table-cell;
vertical-align: middle;
add a comment |
.thumbnail
height: 100px;
display: table;
.thumbnail img
height: 100%;
width: 100%;
display: table-cell;
vertical-align: middle;
.thumbnail
height: 100px;
display: table;
.thumbnail img
height: 100%;
width: 100%;
display: table-cell;
vertical-align: middle;
edited Jun 2 '15 at 12:15
answered Jun 2 '15 at 11:58
Coding EnthusiastCoding Enthusiast
3,19911637
3,19911637
add a comment |
add a comment |
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;
add a comment |
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;
add a comment |
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;
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;
answered Oct 3 '17 at 7:08
raisercostinraisercostin
5,25034456
5,25034456
add a comment |
add a comment |
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;
add a comment |
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;
add a comment |
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;
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;
answered Jun 2 '15 at 11:58
m4lt3m4lt3
19510
19510
add a comment |
add a comment |
.thumbnail img
height: 100%;
width: 100%;
Use this.
add a comment |
.thumbnail img
height: 100%;
width: 100%;
Use this.
add a comment |
.thumbnail img
height: 100%;
width: 100%;
Use this.
.thumbnail img
height: 100%;
width: 100%;
Use this.
answered Jun 2 '15 at 12:01
Danish KhanDanish Khan
10318
10318
add a comment |
add a comment |
.thumbnail
height: 100%;
.thumbnail img
max-height: 100%;
max-width: 100%;
border: 1px solid red;
add a comment |
.thumbnail
height: 100%;
.thumbnail img
max-height: 100%;
max-width: 100%;
border: 1px solid red;
add a comment |
.thumbnail
height: 100%;
.thumbnail img
max-height: 100%;
max-width: 100%;
border: 1px solid red;
.thumbnail
height: 100%;
.thumbnail img
max-height: 100%;
max-width: 100%;
border: 1px solid red;
answered Jun 3 '15 at 16:38
Mr_vasuMr_vasu
8319
8319
add a comment |
add a comment |
(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.)
add a comment |
(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.)
add a comment |
(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.)
(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.)
answered Jun 13 '17 at 6:39
ZZ-bbZZ-bb
2,00612032
2,00612032
add a comment |
add a comment |
<img src="..." class="img-fluid" alt="Responsive image">
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
add a comment |
<img src="..." class="img-fluid" alt="Responsive image">
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
add a comment |
<img src="..." class="img-fluid" alt="Responsive image">
<img src="..." class="img-fluid" alt="Responsive image">
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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