Make two column responsive images of same size - html

I have differently sized images, but want to make them look equal by width and height on the page. What I did:
HTML
<div class="col-lg-6">
<img src = "assets/img/101.jpg" alt="Null" />
</div>
CSS
#images img {
width: 100%;
padding-bottom: 4em;
position: center;
}
But they look like that:
They have different height.
How to make it equal?
Probably I need to crop them by height and center without changing the width. Is it possible?
Explanation from the comments
I have suggested that it will probably be nice to crop them, not resize. Center and crop to the size of smaller ones.

To gain more control over your images it's best to switch to background images. You can then use background-size: cover to fill out the div.
HTML
<div class="col-lg-6">
<div class="image-holder" style="background-image: url('assets/img/101.jpg');">
</div>
</div>
<div class="col-lg-6">
<div class="image-holder" style="background-image: url('assets/img/101.jpg');">
</div>
</div>
CSS
.image-holder {
background-size: cover;
background-position: center center;
height: 400px;
width: 100%;
}
If your images are just static assets it's better to include the image reference in css.

You can't set both height and width at the same time for an image- it will stretch them out. Have made it a 2-column flexbox along with col-lg-6 as per requirement.
See demo below:
.box {
border: 1px solid #ddd;
display: inline-flex;
align-items: center;
justify-content: center;
flex: 1 50%;
min-width: 200px;
}
.container {
display: flex;
flex-wrap: wrap;
flex-direction: row;
}
.col-lg-6.box {
padding: 15px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.3/css/bootstrap.min.css" />
<div class="container">
<div class=" col-lg-6 box">
<img src="http://placehold.it/150x100" alt="Null" />
</div>
<div class=" col-lg-6 box">
<img src="http://placehold.it/75x75" alt="Null" />
</div>
<div class=" col-lg-6 box">
<img src="http://placehold.it/150x50" alt="Null" />
</div>
<div class=" col-lg-6 box">
<img src="http://placehold.it/150x150" alt="Null" />
</div>
</div>

Related

Image Height size doesn't change and only width that change

I know it a bit strange to ask from the title, but I have a problem when changing the size of image inside the carousel. no matter what I did the height of my image doesn't change instead it looks like give an effect like object-fit: cover what I want is to show the image to have size around width: 30vw; and height: 30vh; but every time I change the width its work but when I change the height its not work.
I have some guess such as the container size, the col size, and the div that wrap my image will work if i change their size but in the end its not.
I already read some topic about this :
css-object-fit-contain-is-keeping-original-image-width-in-layout
scaling-centering-and-cropping-image-with-object-fit-and-object-position
but it still not work. Let's say I want to make my image size around width: 360px and height: 360px for example
this is my code:
import React from "react";
// CSS
import './klien.css'
const Klien = () => {
return (
<div className="klien">
<div className="klien-container">
<p className="section-title">Klien Kita</p>
<div className="carousel slide" data-ride="carousel">
<div className="carousel-item active">
<div className="col-12 col-sm-12 col-md-8 col-lg-8 card-center card-size">
<div className="mb-3">
<div className="text-center">
<img className="img-size" src="http://placehold.it/360x360" alt="klien-logo" />
</div>
</div>
</div>
</div>
<div className="carousel-item">
<div className="col-12 col-sm-12 col-md-8 col-lg-8 card-center card-size ">
<div className="mb-3">
<div className="text-center">
<img className="card-img-top img-size" src="http://placehold.it/360x360" alt="klien-logo" />
</div>
</div>
</div>
</div>
<div className="carousel-item">
<div className="col-12 col-sm-12 col-md-8 col-lg-8 card-center card-size">
<div className="mb-3">
<div className="text-center">
<img className="card-img-top img-size" src="http://placehold.it/360x360" alt="klien-logo" />
</div>
</div>
</div>
</div>
<div className="carousel-item">
<div className="col-12 col-sm-12 col-md-8 col-lg-8 card-center card-size">
<div className="mb-3">
<div className="text-center">
<img className="card-img-top img-size" src="http://placehold.it/360x360" alt="klien-logo" />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
);
}
export default Klien;
and this is my css:
.klien{
background-color: #f6f7fd;
min-height: 50vh;
}
.klien .klien-container{
overflow: hidden;
padding-top: 10vh;
}
.klien .section-title{
color: #3b73c5;
font-size: 3em;
font-weight: 500;
text-align: center;
}
.klien .carousel-size{
/* height: 20vh; */
}
.klien .card-center{
margin: 0% auto;
}
.klien .text-center{
text-align: center;
}
.klien .card-size{
max-height: 20vh;
}
.klien .img-container{
height: 20vh;
width: 20vh;
}
.klien .img-size{
width: 30vw;
height: 30vh;
/* object-fit: contain; */
}
can someone help and give explanation about my problem? in first I thought maybe it is because of object-fit: contain but it seems my guess about it is wrong
this is the screenshot:
I would recommend to use a div with a background image, that way you have control of the responsiveness of your list. It requires almost nothing to perform that change.
You need to change your img tags to div
<div
className="img-size"
style={{ backgroundImage: `url(${"http://placehold.it/360x360"})`}}
/>
Your css
.klien .img-size{
width: 30vw;
height: 30vh;
margin: 0 auto;
background-position: center;
background-size: cover;
/* object-fit: contain; */
}
I made a codepen with this. Hope it helps, if you want another approach you can tell me.
Have you tried to change the image size using inline css? For example<img src="url" width="specified with in px or %">

img-fluid not correctly resizing image height

I am working with Bootstrap 4 and am trying to have a grid of 4 images, 2 on top and 2 on bottom. I am using the img-fluid class but the image resizes based on the width only making the image height too large and it is getting cut off. I tried setting max-height: 100% but that didn't work.
What's going wrong?
.images-container {
height: 95vh;
}
.nav-button {
width: 100%;
height: 50%;
margin: auto;
font-size: 5em;
color: black;
}
.footer-container {
text-align: center;
}
.bottom-nav-box {
font-size: 1.5em;
margin: 0;
}
.sim-image {
max-height: 100%;
}
i {
margin: auto;
}
body {
height: 100%;
}
html {
height: 100%;
}
footer {
height: 5vh;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-sm-10 h-100 center-container">
<div class="row images-container">
<div class="row top-images-row h-50">
<div class="w-50 d-inline-block image-div">
<img src="https://lorempixel.com/875/656/" class="sim-image" id="simulatorImageTopLeft">
</div>
<div class="w-50 d-inline-block image-div" id="simulatorImageTopRight">
<img src="https://lorempixel.com/875/656/" class="img-fluid sim-image" id="simulatorImageTopRight">
</div>
</div>
<div class="row bottom-images-row h-50">
<div class="col image-div center-block text-center">
<img src="https://lorempixel.com/875/656/" class="img-fluid sim-image" id="simulatorImageBottomLeft">
</div>
<div class="col image-div center-block text-center">
<div class="row">
<div class="col center-block text-center">
<img src="https://lorempixel.com/875/656/" class="img-fluid sim-image" id="simulatorImageBottomRight">
</div>
<div class="col center-block text-center">
<img src="https://lorempixel.com/875/656/" class="img-fluid sim-image" id="simulatorImageBottomRight">
</div>
</div>
</div>
</div>
</div>
</div>
Not 100% sure I'm interpreting the question correctly, but if you want a 2×2 grid of images then you should just be able to do it relatively quick like this;
html:
<div class="panel">
<img src="blah" />
<img src="blah" />
<img src="blah" />
<img src="blah" />
</div>
css:
.panel {
width = whateversizeyouwant;
height = whateversizeyouwant;
display: flex;
flex-wrap: wrap; //the flex stuff should make it display 2×2
}
.panel > img {
width: 50%;
height: 50%;
}
That should work for any set of 4 images.
If you want them to stay the same aspect ratios then under .panel > img set height: auto. Keep in mind this won't give you a perfect square, and the size of the panel div will impact how the images can be sized.

image scale proportionally within specified column bootstrap 3

I'm trying to get image fit with bootstrap column in a row proportionally within specified height 300px, i have tried so many ways but unfortunately its not fit with column width (my 1st image dimension is 262*380 and 2nd image dimension 546*380 and im using img-responsive class)
I need my image should be like this Expected
but im getting like this Actual
My HTML
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="grid">
<img src="https://static5.thumbtackstatic.com/_assets/images/release/pages/jobs/submodules/gallery/images/lunch-5502ae26.jpg" class="img-responsive" alt="">
</div>
</div>
<div class="col-md-8">
<div class="grid">
<img src="https://static7.thumbtackstatic.com/_assets/images/release/pages/jobs/submodules/gallery/images/lounge-0cd3d802.jpg" class="img-responsive" alt="">
</div>
</div>
</div>
My CSS
.grid {
height: 300px;
border-right: 4px;
}
.grid img {
height: 100%;
}
Try this HTML:
<div class="container">
<div class="row">
<div class="col-md-4 bg-cover grid" style="background-image: url(https://static5.thumbtackstatic.com/_assets/images/release/pages/jobs/submodules/gallery/images/lunch-5502ae26.jpg)">
</div>
<div class="col-md-8 bg-cover grid" style="background-image: url(https://static7.thumbtackstatic.com/_assets/images/release/pages/jobs/submodules/gallery/images/lounge-0cd3d802.jpg)">
</div>
</div>
</div>
with this CSS:
.grid {
height: 300px;
}
.grid img {
height: 100%;
}
.bg-cover {
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
height: 300px
}

Two small align images beside a large image

I'm struggling on how I will code to create a two vertical images and is it possible to lessen the height of the larger image without lessen the width? because I need to fit it on col-md-8 any thoughts about this?
this is the image I need to make.
Click here
HTML and CSS code:
.img-big{ height: 100%;width: 100%; }
<div class="row col-md-8">
<img class="row img-big img-responsive" src="/assets/icons/people-crowd-child-kid-large.jpg"></div>
</div
the above code is what I've used to make the bigger image beside image 2 and 3. the dimension of the large image is 900x767
You can use the flexbox property to achieve what you want and set the image as background.
body, html {
margin: 0;
padding: 0;
color: white;
}
.container {
height: 767px;
display: flex;
}
.left {
background-image: url('http://i.imgur.com/AzeiaRY.jpg');
background-size: cover;
flex: 1;
}
.right {
display: flex;
flex-direction: column;
flex: 0 0 50%;
}
.one {
background-image: url('http://i.imgur.com/AzeiaRY.jpg');
background-size: cover;
flex: 50%;
}
.two {
background-image: url('http://i.imgur.com/AzeiaRY.jpg');
background-size: cover;
flex: 50%;
}
<div class="container">
<div class="left">Left image</div>
<div class="right">
<div class="one">First image</div>
<div class="two">Second image</div>
</div>
</div>
In Bootstrap 5, you can use d-grid gap-x. For example:
HTML
.content {
background-color: transparent;}
.content .left, .content .right {
float: left;}
.full-width-band-hd {
margin-top: -35px;}
.txt-yellow {
color: var(--bs-yellow);}
<section class="container-lg">
<div class="content row">
<h2 class="txt-yellow full-width-band-hd">Head</h2>
<!-- Left Side -->
<h6 class="text-yellow">H6 head</h6>
<h3 class="text-yellow">H3 head</h3>
</div>
<!-- style in content row will become a class later-->
<div class="content row" style="height: 642px;">
<div class="col-md-4 left d-grid gap-3">
<div class="">
<img src="image1" width="100%" height="auto" alt="fp1">
</div>
<div class="">
<img src="image2" width="100%" height="auto" alt="fp2">
</div>
</div>
<!-- End of Left Side -->
<div class="col-md-8 left">
<div class="">
<img src="image3" width="100%" height="auto" alt="fp3">
</div>
</div>
<!-- End of col-md-8 -->
</div><!-- content row -->
</section>
You should format your code like below:
<div class="row">
<div class="col-md-8">
<img class="img-big img-responsive" src="https://en.apkshki.com/storage/5/icon_5dcfce7f86906_5_w256.png"></div>
</div>
<div class="col-md-4">
<img src="https://en.apkshki.com/storage/5/icon_5dcfce7f86906_5_w256.png"></div>
<img src="https://en.apkshki.com/storage/5/icon_5dcfce7f86906_5_w256.png"></div>
</div>
</div>
As you can see the two images at the bottom in col-md-4 if you spread the width 100% the next image will drop below.
You shouldnt really have a class with both a row and a col-md in the class name. (See http://getbootstrap.com/css/)
With regards to reducing the height and not the width are you not able to crop the image down on Paint or Photoshop and upload the image with the correct height?

Need centered aligned text & image

I am working on a bootstrap project and I need to have a text and image and would look similar to a question previously asked here under the link:
How to vertically align both image and text in a DIV using CSS?
Also, I have a background banner with a fixed height of 550px.
I am trying to create this using bootstrap and have also tried using Display: table , display: table-cell, vertical-align: middle; properties but I can' t seem to get right without using putting the height:550px on the both divs containing the text and image.
.overview-banner {
background: url(../img/overview/overview-bg.jpg) no-repeat center center;
background-size: cover;
height: 550px;
.display-table{
display: table;
}
.verticle-center{
display: table-cell;
vertical-align: middle;
}
<section class="overview-banner">
<div class="container-fluid">
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="display-table" style="height:550px;">
<div class="verticle-center" style="height:100%">
<h1>The Multi-Faceted Simpuite</h1>
</div>
</div>
</div>
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="display-table" style="height:550px;">
<div class="verticle-center" style="height:100%">
<img src="{{ STATIC }}assets/img/overview/overview-banner.png" alt="Multi Faceted Simpuite" class="img-responsive img-center-xs">
</div>
</div>
</div>
</div>
</section>
I want to get the result without using height so much in the coding.
Also, I want this to be responsive when it appears in a mobile device.
Please advise if there is any other way to do it bootstrap which can be responsive and has centered text and image as per the banner height of 550px and no need of mentioning the height so often.
There was a small mistake, that you have missed the closing } in the first CSS declaration, which made the whole CSS obsolete. And also consider giving a text-align: center too. You don't exactly need the height to be specified here. You can use this way:
.overview-banner {
background: url(../img/overview/overview-bg.jpg) no-repeat center center;
background-size: cover;
}
.display-table{
display: table;
}
.verticle-center{
display: table-cell;
vertical-align: middle;
text-align: center;
}
<section class="overview-banner">
<div class="container-fluid">
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="display-table">
<div class="verticle-center">
<h1>The Multi-Faceted Simpuite</h1>
</div>
</div>
</div>
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="display-table">
<div class="verticle-center">
<img src="{{ STATIC }}assets/img/overview/overview-banner.png" alt="Multi Faceted Simpuite" class="img-responsive img-center-xs">
</div>
</div>
</div>
</div>
</section>
What browsers are you trying to support? If its most of the latest ones then I suggest you use "display:flex"; Browser Support
<div class="align">
<div class="align-item">
<img src="http://lorempixel.com/400/200/">
</div>
</div>
<style>
html,body {
width:100%;
height:100%;
}
.align {
width:100%;
height:100%;
display: flex;
align-items: center;
justify-content: center;
}
.align-item {
max-width: 50%;
}
</style>
http://codepen.io/richardhealy/pen/zGwbLz