I'm using bootstrap v4 cards in my layout and unfortunately, the images are distorted in Internet Explorer 11. It seems that IE completely ignores the height: auto attribute given by the img-fluid class. Is it necessary to apply a custom height to the card images? However, the cards render perfectly in Chrome and Firefox. Interestingly, if I change the engine to IE 10 (in the F12 console), the problem is gone.
As images with class img-fluid which are not wrapped by cards are displayed respecting their original ratio, I think the problem corresponds to the card layout.
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="card">
<img class="card-img-top img-fluid" src="img/1.jpg" alt="Step 1" width="600" height="400" />
<div class="card-block">
<h3 class="card-title">Step 1</h3>
<p class="card-text">Text 1</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<img class="card-img-top img-fluid" src="img/2.jpg" alt="Step 2" width="600" height="400" />
<div class="card-block">
<h3 class="card-title">Step 2</h3>
<p class="card-text">Text 2</p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<img class="card-img-top img-fluid" src="img/3.jpg" alt="Step 3" width="600" height="400" />
<div class="card-block">
<h3 class="card-title">Step 3</h3>
<p class="card-text">Text 3</p>
</div>
</div>
</div>
</div>
</div>
I had the same problem, but when I wrapped the content of the card in a <a> tag to make it clickable and it fixed itself, but the height of the card was wrong in IE11, I fixed that by adding height: 100% to the <a> tag :
<div class="col-md-4">
<div class="card h-100">
<a href="/document" style="height:100%;">
<img class="card-img-top img-fluid" src="foo.jpg">
<div class="card-block">
<h4>doc number 4</h4>
<p class="card-text">yada yada</p>
</div>
</a>
</div>
</div>
If you don't want your card to be clickable, you could replace the <a> by a <div> (I haven't tested it).
Bootstrap 4 is still in alpha so you should expect various issues.
The issue with image height in IE 11 has already been identified and you can track it here:
https://github.com/twbs/bootstrap/issues/21885
Addding height:100%; can also be done to:
.card img{
height:100%;
}
if you dont want to add another class etc to fix issues in explorer.
the solution is to add d-block (display:block) to the parent div:
<div class="card d-block">
<img class="card-img-top" src="someimage.jpg">
</div>
use overflow: hidden for external container
Inline styling do the magic...
eg.: style="height: 100%; overflow: hidden;"
This is a known issue. You can fix this by adding width: 100%;
According to docs:
SVG images and IE 10 In Internet Explorer 10, SVG images with
.img-fluid are disproportionately sized. To fix this, add width: 100%
\9; where necessary. This fix improperly sizes other image formats, so
Bootstrap doesn’t apply it automatically.
You can check the docs in this link: https://getbootstrap.com/docs/4.3/content/images/
Based on the comments in the issue tracker the only thing that worked for me in IE11 was adding a height: 0.01px to the card image.
To make it IE specific I've added the following rule:
#media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
/* IE10, IE11 */
.card-img-top {
min-height: 0.01px;
}
}
In my case I also have a .card-footer which failed to render properly in IE11 with all previous answers. I'm using Bootstrap 4.1.3.
The best solution for me was to modify IE only.
Turns out it was the card-body text causing the most issues because it wasn't wrapping properly.
The card element did also need display:block; but again, only on IE.
No need to add block for other browsers, as it can affect using the mt-auto class or other utilities.
Here's the full solution:
<div class="card ie-block">
<img src="https://picsum.photos/500/300" class="card-img-top" />
<div class="card-body">
<div class="ie-wrapper"><h5 class="card-title ie-inner">Card title</h5></div>
<div class="ie-wrapper"><p class="card-text ie-inner">Some quick example text to build on the card title and make up the bulk of the card's content.</p></div>
Go somewhere
</div>
</div>
Then, add the following IE10+ only CSS:
/* IE10+ specific styles go here */
#media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
.ie-block {
display: block;
}
.ie-wrapper {
display: flex;
}
.ie-inner {
flex-basis: 100%;
}
}
I had the same issue. Just added the regular old school class "img-responsive" & seems to be working fine in Chrome now.
<img class="card-img-top img-responsive" src="images/your-image.jpg" alt="Description">
Update BS version 4:
img-responsive
is now
img-fluid
Related
Why does the border color of the image turn red on Safari Browser on Mac but appears grey(expected color) on other non safari browsers ? The website I am working on is based on Drupal 7.
Can anyone here explain the reason behind this behavior?
<style>
.img-full-width {
width: 100%;
border: solid 1px #cccaca !important;
}
</style>
<div class="container">
<div class="row">
<div class="col-md-4 col-xs-6">
<img src=" http://media.istockphoto.com/vectors/language-translation-line-icon-outline-vector-sign-linear-pictogram-vector-id668592940?s=170x170" alt="" class="img-responsive img-full-width">
<div class="row">
<div class="col-md-7 col-sm-7">
<div class="product-pricing product-pricing-min">
<h6>Random Text</h6>
<p>From $.1599.00</p>
</div>
</div>
<div class="col-md-5 col-sm-5">
Select
</div>
</div>
</div>
</div>
</div>
I tried set-resetting css properties in css & also using jquery. Also tested the page on safari for windows, and the display was as expected(grey border) instead of red which appears in safari for Mac.
On all other browsers the css works fine. Also the bug wasn't there during the initial release of the site a year ago. So I assume its a bug in Safari-Mac.
I am having trouble centering the columns on bootstrap when the screen is sm or xs.
The fiddle is here https://jsfiddle.net/iggyfiddle/DTcHh/34028/. Here is what I am talking about:
When the screen is large (or medium), I have no problem. It appears centered.
When the screen starts to get smaller, it starts to become noticeable. If you notice, the whole column stack leans to the left, leaving some space on the right (I added red bg for emphasis. Hard to tell when bg is white).
When screen is xs, it is even more noticeable. Note that everything is leaning to the left, leaving a lot of space on the right.
I saw a popular SO post that addressed similar issue here. The solution suggested float: none; margin: 0 auto;, which I did - but it didn't do anything. I also tried adding center-block class, but the result is still nothing.
What do I have to do to center my columns? My goal is on xs screen, I want to have one column stacked up. When it is on sm screen, I want to have two columns, side-by-side, stacked. Anything larger should have 4 adjacent columns.
It's because you're using a width on the .card. Adding margin: 0 auto to the .card class will solve your issue.
I also tried adding center-block class, but the result is still nothing.
That's because you're using bootstrap 3.0. .center-block was added in bootstrap 3.1. If you can upgrade to 3.1 (or even better, the current release 3.3.7), .center-block fixes it.
If not, you can use #media (max-width: 992px) { .card { margin: auto; } }
I used both in my solution below.
/* Latest compiled and minified CSS included as External Resource*/
/* Optional theme */
#import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
body {
margin: 10px;
}
.col-centered {
margin: 0 auto;
}
#media (max-width: 992px) {
.col-centered .card {
margin: auto;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-md-3 col-sm-6 col-xs-12 col-centered center-block">
<div class="card center-block" style="width: 200px;">
<img class="card-img-top img-circle img-responsive" style="margin:0 auto;" src="http://placekitten.com/g/150/150" alt="Card image cap">
<div class="card-block">
<h4 class="card-title text-center">Card title 1</h4>
<p class="card-text text-justify">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
</div>
<div class="col-md-3 col-sm-6 col-xs-12 col-centered center-block">
<div class="card center-block" style="width: 200px;">
<div class="card-block">
<h4 class="card-title text-center">Card title 2</h4>
<p class="card-text text-justify">Omnichannel CPM call-to-action low hanging fruit branding. Inbound holistic tweens dynamic content branding granular. Mission critical lean content snackable content drone inbound. Leading the pack buzzword flat design click bait B2C conversions millennials. Alignment pass the clap content marketing multiple points of entry context.</p>
</div>
</div>
</div>
<div class="col-md-3 col-sm-6 col-xs-12 col-centered center-block">
<div class="card" style="width: 200px;">
<img class="card-img-top img-circle img-responsive" style="margin:0 auto;" src="http://placekitten.com/g/150/150" alt="Card image cap">
<div class="card-block">
<h4 class="card-title text-center">Card title 3</h4>
<p class="card-text text-justify">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</div>
</div>
<div class="col-md-3 col-sm-6 col-xs-12 col-centered center-block">
<div class="card" style="width: 200px;">
<div class="card-block">
<h4 class="card-title text-center">Card title 4</h4>
<p class="card-text text-justify">Conversions buzzword trending brand voice B2C curated ideation. Branding user-friendly hashtag tablet click-through rate disrupt iterative. CRM alignment The Cloud visibility taste makers. CRM snackable content engagement millennials. Content marketing integrated big data. Tablet shoptimization intuitive top influencers reaching out.</p>
</div>
</div>
</div>
</div>
You have used fixed hieght 200px, I just run the code in fiddle. If you remove height:200px; and use .text-center class with card-block section then everything will be centered. But the main issue is you have used bootstrap-3.0.0, use the latest version of Bootstrap the issue will be fixed instantly....
i think it's a duplicate of this link
Since v3.0.1 Bootstrap has a built-in class named center-block that uses margin: 0 auto but is missing float:none. You can add that to your CSS to make it work with the grid system.
check the above link may be helpfull for you.
I have a grid section in which I show posts and I display photos and text. However, no photos are the same size and that is inevitable so I try to make them the same size. I cut to the chase, the problem is the width:auto; stretches the image horizontally.
<div class="item_grid item2">
<div class="panel">
<div style="height:50px; overflow:hidden;">
<h4 class="recent-post-header">
Title
</h4>
</div>
<div style="height:300px; overflow:hidden;">
//Problem is Here
<img src="/Image" alt="img_preview" style="height:100%; width:auto; " /> /
</div>
<div style="height:100px; overflow:hidden">
<div class="clearfix post_date">
<span class="pull-left">DateCreated</span>
</div>
<p>Description</p>
</div>
<p> Read More <i class="icon-angle-right"></i></p>
</div>
</div>
Is there any way to allow the width of the image overflow and then hide it?
use
<img src="/Image" alt="img_preview" style="height: 100%; width: 100%; object-fit: cover" >
eventhoug ie doesnt support object-fit
Short and straightforward answers
style="height:100%; object-fit: cover;"
How do I change the width of the <a> tag below exactly as the test_small.jpg image width?
<div class="row">
<div class="col-md-5">
<a class="fancybox thumbnail" href="/assets/images/gallery/test.jpg">
<img class="img-responsive" src="test_small.jpg">
</a>
</div>
<div class="col-md-7">
...
</div>
</div>
I tried using:
<a class="fancybox thumbnail" style="width: auto" href="/assets/images/gallery/test.jpg">
without success.
Thanks.
EDIT: http://www.bootply.com/PGsq7xJeOt
You could just add an auto width. You will need to specify display: block for this to take effect.
.fancybox.thumbnail {
display: block;
width: auto;
}
I'd add class to that a .. for example: .customThumbnail
HTML:
<a class="fancybox thumbnail customThumbnail" href="/assets/images/gallery/test.jpg">
<img class="img-responsive" src="test_small.jpg">
</a>
CSS:
a.customThumbnail {display: block; width: 200px;}
You can use any width here (within col-md-5), since your image is responsive - it will adjust.
Also, try resetting padding (as the "a" might have some padding around it).
a.customThumbnail {display: block; width: 200px; padding: 0}
Although, a JSFiddle would be the best :)
I have an active example on ToWho.
<div class="row">
<div class="col-md-5">
<a href="/assets/images/gallery/test.jpg">
<div class="content"> <!-- This div isn't necessary, but is helpful for organizing -->
<img class="img-responsive" src="test_small.jpg" alt="Small Images">
</div>
</a>
</div>
<div class="col-md-7"></div>
</div>
Why it's not working is hard to solve without a fiddle. The anchor shouldn't need anything special to make it take up the space of the div, especially since it's in a Bootstrap grid element.
Try to make a new class giving it width:100% or make it an inline style.
<div class="row">
<div class="col-md-5">
<img class="image-responsive" style="width:100%;" src="test_small.jpg"/> </div>
<div class="col-md-7">
...
</div>
</div>
Is it possible to use 2 responsive images side by side with same height with Bootstrap 3? At the moment the col-sm-4 hasn't the same height.
<div class="container">
<div class="row">
<div class="col-sm-4">
<img class="img-responsive" src="http://placehold.it/400x400" />
</div>
<div class="col-sm-8">
<img class="img-responsive" src="http://placehold.it/800x400" />
</div>
</div>
</div>
Demo Fiddle: http://jsfiddle.net/u9av6/3/
Thanks!
try this:
<div class="col-sm-4"><img src="http://placehold.it/400x400" height="220" /></div>
<div class="col-sm-8"><img src="http://placehold.it/800x400" height="220" /></div>
Here's a working version, with jsfiddle demo.
<div class="col-sm-4"><img style="max-height:220px" src="http://placehold.it/400x400" /></div>
<div class="col-sm-8"><img style="max-height:220px" src="http://placehold.it/800x400" /></div>
Maybe your problem is that in your code, the padding is not considering.
Your 400px and 800px is nice, but with padding considering it's not good.
In this fiddle : http://jsfiddle.net/Lrc5t/1/ , with no padding, they keep the same height. But it's not nice without padding...
The padding in each .row is 15px left and right.
html:
<div class="row">
<div class="col-sm-4 nopadding"><img class="img-responsive" src="http://placehold.it/400x400"></div>
<div class="col-sm-8 nopadding"><img class="img-responsive" src="http://placehold.it/800x400"></div>
</div>
css:
.nopadding{
padding-left: 0px !important;
padding-right:0px !important;
}
UPDATE :
fiddle : http://jsfiddle.net/Lrc5t/2/
Without paddding is not nice so , just inverse in adding extra padding to right image :
<div class="row">
<div class="col-sm-4"><img class="img-responsive" src="http://placehold.it/400x400"></div>
<div class="col-sm-8 nopadding-two"><img class="img-responsive" src="http://placehold.it/800x400"></div>
</div>
.nopadding-two{
padding-right:45px !important;
}
ps : You can choose to add your padding at left instead or right... in order to keep the padding in middle. And... nopadding-one and text-right class are to delete...(I forgot)...
UPDATE AFTER COMMENT:
*Why 45px ?*
Image 1 is float:left so it has just the padding-right at 15px
Image 2 has padding left and right at 15px {=30px}
So in order do equality (to get same constraints) you need to transmit the total padding to image 2
To make the images displaying side by side, you need to do three things:
1st: make all your images responsive in the html file like this:
<div class="row">
<div class="col-xs-3 left-image" >
<img class="img-responsive" src="../img/fourthimg.jpg">
</div>
<div class="col-xs-9 right-image">
<img class="img-responsive" src="../img/firstimg.jpg" >
</div>
</div>
This is for putting two images side by side. You could have as many images as possible.
2nd: Inside your css, give the height to these images like this:
.img-responsive {display:block; height: 600px; width: 100%;}
The width is set to 100% meaning that both (for this example)/all the images would cover the 100% part of the column width provided in your html code.
3rd (Most important) : CSS has this property to automatically leave margins/paddings on right and left when you put an image inside a div and this padding is associated with the image or any other element that you want to put inside a div.
To tackle this, go to you css file and for each image, set the left-padding and right padding to 0px just like this:
.right-image{
padding-left:0px;
padding-right:0px;
}
.left-image{
padding-right: 0px;
padding-left: 0px;
}
This is a working example and explanation of how to put in images side by side using bootstrap!
Check this code. This code will look for the smallest height of the image and set it as max-height of the other images. The rest of the image will be hidden. Check it out.
<script>
setTimeout(function () {
equalheight('.portfolio-item');
}, 3000);
function equalheight($that) {
$minHeight = 0;
$($that).each(function (index) {
$thisHeight = $(this).children('.portfolio-link').innerHeight();
if ($minHeight == 0) {
$minHeight = $thisHeight;
} else {
if ($minHeight > $thisHeight) {
$minHeight = $thisHeight;
}
}
});
$($that).children('.portfolio-link').css('max-height', $minHeight);
$($that).children('.portfolio-link').css('overflow', 'hidden');
}
</script>
My html is
<div class="col-md-4 col-sm-6 portfolio-item">
<a href="#portfolioModal1" class="portfolio-link" data-toggle="modal" style="max-height: 225px; overflow: hidden;">
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<i class="fa fa-plus fa-3x"></i>
</div>
</div>
<img src="images/trip-01.jpg" class="img-responsive" alt="">
</a>
<div class="portfolio-caption">
<h4>Round Icons</h4>
<p class="text-muted">Graphic Design</p>
</div>
</div>
<div class="col-md-4 col-sm-6 portfolio-item">
<a href="#portfolioModal2" class="portfolio-link" data-toggle="modal" style="max-height: 225px; overflow: hidden;">
<div class="portfolio-hover">
<div class="portfolio-hover-content">
<i class="fa fa-plus fa-3x"></i>
</div>
</div>
<img src="images/trip-02.jpg" class="img-responsive" alt="">
</a>
<div class="portfolio-caption">
<h4>Startup Framework</h4>
<p class="text-muted">Website Design</p>
</div>
</div>
if you want constant height, should add these properties:
height: 200x ; # any constant height
object-fit: cover;
Or else you want width constant, should add these properties:
width: 200px ; # any constant height
object-fit: cover;
object-fit: cover, fixed the problem of stretching up of the image in my case.