Equal height grid in Bootstrap with multiple dimension images with Flexbox - html

I have various images of different dimensions that need to be the same height within a bootstrap grid.
How can I replicate this equal size display in Bootstrap? I have tried "flex 1" on the child items with no joy and "flex: 1 0 0%;" used at source and a few other equal height tutorials on the web with no joy.
I think the solution here is making equal sized rectangle divs, but interested in the way of getting equal height divs with flexbox of all proportions too.

If you control the image files, your best option is probably going to be manually cropping the images into the correct dimensions.
If you don't control the source images (if you're loading from a remote service such as instagram as in the demo), then you'll get the best results by setting an explicit height on your divs and then loading the images as backgrounds with background-size: cover;.
https://developer.mozilla.org/en-US/docs/Web/CSS/background-size

They basically have a wrapper that has all those rows inside it with a fixed responsive width (media queries they define a fixed width for each screen size) and display:flex/flex-direction:column to those rows stack on top of each other, then those rows are also flexed, with flex-direction:row unlike your code each row has 3 divs those div has flex:1 0 0% so they split the width evenly,and of them each have an img inside each img has a set of defined sizes in the srcset attribute which have equal heights.
So you see the fixed width on the wrapper is divided between the children, and the height is defined by the images.
example below
I splitted your example into two rows each with 3 images, instead of doing the same thing they did with srceset attribute to make the images responsive, i'm just gonna give them a fixed height, for the sake of this explanation.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
display: flex;
flex-direction: column;
max-width: 935px !important;
/* Because in here bootsrtap comes after the editor css*/
}
.container>.row {
display: flex;
flex-direction: row;
}
.container>.row>div {
flex: 1 0 0%;
}
.container>.row>div img {
max-width: 100%;
height: 293px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
<div class="container">
<h1 class="my-4 text-center text-lg-left"></h1>
<div id="" class="row text-center text-lg-left">
<div class="col-lg-4 col-sm-6">
<a href="" class="d-block mb-4 h-100" target="_blank">
<img class="img-fluid img-thumbnail" src="https://www.instagram.com/p/BjiCy5uDPHp/media/?size=l" alt="">
</a>
</div>
<div class="col-lg-4 col-sm-6">
<a href="" class="d-block mb-4 h-100" target="_blank">
<img class="img-fluid img-thumbnail" src="https://www.instagram.com/p/Bjhw_0DDAKB/media/?size=l" alt="">
</a>
</div>
<div class="col-lg-4 col-sm-6">
<a href="" class="d-block mb-4 h-100" target="_blank">
<img class="img-fluid img-thumbnail" src="https://www.instagram.com/p/BjhXUb5DVo4/media/?size=l" alt="">
</a>
</div>
</div>
<div id="" class="row text-center text-lg-left">
<div class="col-lg-4 col-sm-6">
<a href="" class="d-block mb-4 h-100" target="_blank">
<img class="img-fluid img-thumbnail" src="https://www.instagram.com/p/BjhF2fDjc6E/media/?size=l" alt="">
</a>
</div>
<div class="col-lg-4 col-sm-6">
<a href="" class="d-block mb-4 h-100" target="_blank">
<img class="img-fluid img-thumbnail" src="https://www.instagram.com/p/Bjgz6KJDw2S/media/?size=l" alt="">
</a>
</div>
<div class="col-lg-4 col-sm-6">
<a href="" class="d-block mb-4 h-100" target="_blank">
<img class="img-fluid img-thumbnail" src="https://www.instagram.com/p/Bjggi3mjTxf/media/?size=l" alt="">
</a>
</div>
</div>
</div>

Related

HTML - Resposive photos gallery cover 100% screen

How can i set div with photos on all available space (now in div .row have big margins) and set one height for all photos in all rows (i have vertical and horizontal photos) and keep responsiveness? Margins in row are the same all the time. Ofc the middle photo will be wider to keep the proportions.
HTML:
<main>
<div class="container">
<div class="row justify-content-sm-center">
<div class="col-lg-4 col-md-6 col-sm-12">
<figure class="description">
<img src="img/projects/home/1.jpg" class="img-fluid img home-photos">
</figure>
</div>
<div class="col-lg-4 col-md-6 col-sm-12">
<figure class="description">
<img src="img/projects/home/2.jpg" class="img-fluid img home-photos">
</figure>
</div>
<div class="col-lg-4 col-md-6 col-sm-12">
<figure class="description">
<img src="img/projects/home/3.jpg" class="img-fluid img home-photos">
</figure>
</div>
</div>
</div>
If I'm understanding the question properly this CSS should work.
.row {
display: flex;
justify-content: space-around;
}
.img {
height: 100vh;
width: 45vh; //play with this to get the effect you desire. You may need to target the middle picture individually.
}

Bootstrap 5: Carousel inside Card won't maintain the same size

The problem is shown in this GIF:
https://gifyu.com/image/B5nC
I'm using Bootstrap 5 to have a carousel inside a card. Although the images are shown properly, the card resizes as the images change. I want to prevent that and have a constant size for all the images.
Here's the relevant code:
<div class="col">
<div class="card h-100">
<div class="card-img-top w-100">
<div id="carouselExampleControls" class="carousel slide >
<div class="carousel-inner">
<div class="carousel-item active
<img src="1.png" class="d-block w-100 " alt="..." >
</div>
<div class="carousel-item active
<img src="2.png" class="d-block w-100 " alt="..." >
</div>
<div class="carousel-item active
<img src="3.png" class="d-block w-100 " alt="..." >
</div>
</div>
<Button stuff, not so important...>
</div>
</div>
<div class="card-body">
<h5 class="card-title">a title</h5>
<p class="card-text">Some text.</p>
</div>
<div class="card-footer">
Some Text here.
</div>
</div>
</div>
Any ideas?
What you'd want to do, is add a fixed height or width to the image.
Add some css to the img tag. With that you can adjust the height of the image and center the image.
Something like so:
.carousel img {
height: 220px;
width: 100%;
object-fit: cover;
object-position: center;
}
The object-fit: cover; makes it so that the image will fit and not being stretched out. With object-position: center; it centers the image of the view. In this case it centers image on the height of 220px.
Here's a working example: https://www.codeply.com/p/y86ZKljAZS

Bootstrap img-responsive class not working correctly

I am currently having a problem where the bootstrap img-responsive class isn't working as it should due to me needing the image to be as far right in the div box as possible. I have two identically sized arrows which surrounds titles of my site. When the browser is scaled down to mobile size, the left arrow appears smaller and more distorted than the right counterpart.
Full Sized Title
Phone Sized Title
HTML:
<div class="row">
<div class="col-lg-3"> </div>
<div class="col-xs-3 col-lg-2 arrow-right">
<img class="img-responsive img-right" src="img/arrow-right.png" alt="">
</div>
<div class="col-xs-6 col-lg-2 text-center">
<h2 class="section-heading">RSVP</h2>
</div>
<div class="col-xs-3 col-lg-2 arrow-left">
<img class="img-responsive img-left" src="img/arrow-left.png" alt="">
</div>
<div class="col-lg-3"> </div>
</div>
CSS:
.arrow-right {
padding-top: 12px;
}
.arrow-left {
padding-top: 12px;
padding-left: 0;
}
#media (min-width: 768px) {
.img-right {
display: block;
margin: auto;
margin-left: 34px;
}
.img-left {
margin: auto;
margin-right: 30px;
}
}
My question would be, is there an easier way to get these arrows as close to the titles as possible and have them scale down to phone sized perfectly?
Change the XS and make 4/4/4
<div class="row">
<div class="col-lg-3"> </div>
<div class="col-xs-4 col-lg-2 arrow-right">
<img class="img-responsive img-right" src="img/arrow-right.png" alt="">
</div>
<div class="col-xs-4 col-lg-2 text-center">
<h2 class="section-heading">RSVP</h2>
</div>
<div class="col-xs-4 col-lg-2 arrow-left">
<img class="img-responsive img-left" src="img/arrow-left.png" alt="">
</div>
<div class="col-lg-3"> </div>
</div>
I think the blurry image is due to display: block, for getting the image as close to the text as possible you could consider using ::after or ::before pseudo-elements. Also you could try the following HTML:
<div class="col-xs-3 col-lg-2 arrow-right">
</div>
<div class="col-xs-12 col-lg-6 text-center">
<img class="img-responsive img-right" src="img/arrow-right.png" alt="">
<h2 class="section-heading">RSVP</h2>
<img class="img-responsive img-left" src="img/arrow-left.png" alt="">
</div>
</div>
</div>
Also, could you post a fiddle or http://www.bootply.com/?
EDIT -- (after bootply response)
using a little CSS i got it working (without the use of media queries etc.). The CSS is now a lot less and I hope this is what you are looking for (because the images are as close as possible to the text). Using float: left to the img, h2 and a little padding-top: 24px for the images got it lined up. See bootply:
http://www.bootply.com/2Hp6stSs9B

Stretch image to fit full container width bootstrap

I have an image that's 1300px wide, using bootstrap I want this image to fill the full width of my container which is set to 1300px. I create a row, give it a full 12 columns and then add in the image with a class of image responsive. With this set up I get the output below.
I want my image to stretch all the way along to where my image is in my content, here is my code.
<div class="row">
<div class="container">
<div class="col-md-12">
<img src="<?php bloginfo('template_directory'); ?>/assets/img/homeBanner.jpg" alt="placeholder 960" class="img-responsive"/>
</div>
</div>
</div>
The image is set to width 100% so not sure why it isn't filling the container.
In bootstrap 4.1, the w-100 class is required along with img-fluid for images smaller than the page to be stretched:
<div class="container">
<div class="row">
<img class='img-fluid w-100' src="#" alt="" />
</div>
</div>
see closed issue: https://github.com/twbs/bootstrap/issues/20830
(As of 2018-04-20, the documentation is wrong: https://getbootstrap.com/docs/4.1/content/images/ says that img-fluid applies max-width: 100%; height: auto;" but img-fluid does not resolve the issue, and neither does manually adding those style attributes with or without bootstrap classes on the img tag.)
Check if this solves the problem:
<div class="container-fluid no-padding">
<div class="row">
<div class="col-md-12">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=1300%C3%97400&w=1300&h=400" alt="placeholder 960" class="img-responsive" />
</div>
</div>
</div>
CSS
.no-padding {
padding-left: 0;
padding-right: 0;
}
Css class no-padding will override default bootstrap container padding.
Full example here.
#Update
If you use bootstrap 4 it could be done even simpler
<div class="container-fluid px-0">
<div class="row">
<div class="col-md-12">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=1300%C3%97400&w=1300&h=400" alt="placeholder 960" class="img-responsive" />
</div>
</div>
</div>
Updated example here.
First of all if the size of the image is smaller than the container, then only "img-fluid" class will not solve your problem. you have to set the width of image to 100%, for that you can use Bootstrap class "w-100".
keep in mind that "container-fluid" and "col-12" class sets left and right padding to 15px and "row" class sets left and right margin to "-15px" by default.
make sure to set them to 0.
Note:
"px-0" is a bootstrap class which sets left and right padding to 0 and
"mx-0" is a bootstrap class which sets left and right margin to 0
P.S. i am using Bootstrap 4.0 version.
<div class="container-fluid px-0">
<div class="row mx-0">
<div class="col-12 px-0">
<img src="images/top.jpg" class="img-fluid w-100">
</div>
</div>
</div>
Here's what worked for me. Note: Adding the image within a row introduces some space so I've intentionally used only a div to encapsulate the image.
<div class="container-fluid w-100 h-auto m-0 p-0">
<img src="someimg.jpg" class="img-fluid w-100 h-auto p-0 m-0" alt="Patience">
</div>
container class has 15px left & right padding, so if you want to remove this padding, use following, because row class has -15px left & right margin.
<div class="container">
<div class="row">
<img class='img-responsive' src="#" alt="" />
</div>
</div>
Codepen: http://codepen.io/m-dehghani/pen/jqeKgv
This will do the same as many of the other answers, but will make sides flush with the window, so there is no scroll bars.
<div class="container-fluid">
<div class="row">
<div class="col" style="padding: 0;">
<img src="example.jpg" class="img-responsive" alt="Example">
</div>
</div>
</div>

Make rectangular thumbnails square for large screen size in a bootstrap grid

I'm working on implementing a data grid of square images in bootstrap. One requirement is that the grid remain square and the images shrink on transition to smaller screen widths. Below I have my current implementation, it works great for large images, but when I try to use an image below a certain size the thumbnails appear square for large screen widths. Can some one advise me on how to adapt this for smaller images? Also I have a strong preference to do this with out adding css and if that's not possible I'd like to find a minimally invasive solution.
fiddle
html:
<div class="container">
<div class="row">
<div class="col-xs-6">
<a class="thumbnail" href="http://www.google.com"><img class="img-responsive img-rounded" src="http://www.op-art.co.uk/op-art-gallery/var/albums/your-op-art/GDHarley_OP-ART_%2311.jpg?m=1382213140" /></a>
</div>
<div class="col-xs-6">
<a class="thumbnail" href="http://www.google.com"><img class="img-responsive img-rounded" src="http://www.op-art.co.uk/op-art-gallery/var/albums/your-op-art/GDHarley_OP-ART_%2311.jpg?m=1382213140" /></a>
</div>
</div>
<div class="row">
<div class="col-xs-6">
<a class="thumbnail" href="http://www.google.com"><img class="img-responsive img-rounded" src="http://davidsimpson.me/wp-content/uploads/2014/04/icon1281.png" /></a>
</div>
<div class="col-xs-6">
<a class="thumbnail" href="http://www.google.com"><img class="img-responsive img-rounded" src="http://davidsimpson.me/wp-content/uploads/2014/04/icon1281.png" /></a>
</div>
</div>
</div>
Smaller images need to have 100% width therefore you have to use CSS code, simply add this CSS class:
.full-width
{
width:100%;
}
and then use it in the tag:
<img class="img-responsive img-rounded full-width" ... />