I have 6 images wrapped inside an outer div.
I'd like to see 2 images per row in the mobile version, so there should be 3 columns with 2 images per row.
I have this HTML:
* {
box-sizing: border-box;
}
img {
width: auto;
max-width: 100%;
height: auto;
max-height: 100%;
}
.picture-box {
width: 70%; /* limit screen width - max width could have been used aswell */
margin: 0 auto; /* center content */
display: flex;
flex-direction: column;
flex-wrap: wrap;
}
.ring {
padding: 10px;
text-align: center; /* Center ring div */
}
#media screen and (min-width: 1200px) {
.ring {
width: 25%;
}
}
#media screen and (max-width: 1199px) {
.ring {
width: 33.33%;
}
}
#media screen and (max-width: 768px) {
.ring {
width: 50%;
}
.picture-box {
width: 100%;
}
}
.thumb {
display: inline-block;
max-width: 200px;
padding: 10px;
border: 1px solid blue;
}
<div class="picture-box">
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
</div>
Working JSFiddle Example
I tried to change flex-direction from row to column, but it did not help.
I may need to write widths for them, but do not know how and now I cannot make them into a column.
How can I solve that?
Is this what you are looking for?
I used width like you asked about in your question - this is one way to do it.
This way you can control how many boxes (.ring's) you want to show in each breakpoint.
* {
box-sizing: border-box;
}
img {
width: auto;
max-width: 100%;
height: auto;
max-height: 100%;
}
.picture-box {
width: 70%; /* limit screen width - max width could have been used aswell */
margin: 0 auto; /* center content */
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.ring {
padding: 10px;
text-align: center; /* Center ring div */
}
#media screen and (min-width: 1200px) {
.ring {
width: 25%;
}
}
#media screen and (max-width: 1199px) {
.ring {
width: 33.33%;
}
}
#media screen and (max-width: 768px) {
.ring {
width: 50%;
}
.picture-box {
width: 100%;
}
}
.thumb {
display: inline-block;
max-width: 200px;
padding: 10px;
border: 1px solid blue;
}
<div class="picture-box">
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
<div class="ring">
<div class="thumb">
<img src="https://via.placeholder.com/200">
</div>
</div>
</div>
JSFiddle example
Related
.row {
display: flex;
flex-wrap: wrap;
padding: 0 4px;
}
.column {
flex: 25%;
max-width: 25%;
padding: 0 4px;
}
.column img {
margin-top: 8px;
vertical-align: middle;
width: 100%;
}
#media screen and (max-width: 800px) {
.column {
flex: 50%;
max-width: 50%;
}
}
#media screen and (max-width: 600px) {
.column {
flex: 100%;
max-width: 100%;
}
}
<table align="center">
<tr>
<td align="center">
<div class="row">
<div class="column">
<img src="pics/photos/sample1.png">
<img src="pics/photos/sample2.png">
<img src="pics/photos/sample3.png">
</div>
<div class="column">
<img src="pics/photos/sample4.png">
<img src="pics/photos/sample5.png">
<img src="pics/photos/sample6.png">
</div>
<div class="column">
<img src="pics/photos/sample7.png">
<img src="pics/photos/sample8.png">
<img src="pics/photos/sample9.png">
</div>
</div>
</td>
</tr>
</table>
Someone maybe know why my div isn't go to the center and keep stay on the side?
No matter what I writing with margin or align it keep stay on the side (on the body CSS I've putted direction: rtl; if that matter.
HTML:
<table align="center">
<tr>
<td align="center">
<div class="row">
<div class="column">
<img src="pics/photos/sample1.png">
<img src="pics/photos/sample2.png">
<img src="pics/photos/sample3.png">
</div>
<div class="column">
<img src="pics/photos/sample4.png">
<img src="pics/photos/sample5.png">
<img src="pics/photos/sample6.png">
</div>
<div class="column">
<img src="pics/photos/sample7.png">
<img src="pics/photos/sample8.png">
<img src="pics/photos/sample9.png">
</div>
</div>
</td>
</tr>
</table>
CSS:
.row {
display: flex;
flex-wrap: wrap;
padding: 0 4px;
}
.column {
flex: 25%;
max-width: 25%;
padding: 0 4px;
}
.column img {
margin-top: 8px;
vertical-align: middle;
width: 100%;
}
#media screen and (max-width: 800px) {
.column {
flex: 50%;
max-width: 50%;
}
}
#media screen and (max-width: 600px) {
.column {
flex: 100%;
max-width: 100%;
}
}
Thank you all for the help!
from what I can understand you want your "column" divs to be centered inside row div. I will suggest you to learn flex-box and grid which makes thing easier.
I have added only two lines of code in your ".row" class
1.display:flex
2.justify-content:center
Below is my solution.
.row {
display: flex;
flex-wrap: wrap;
padding: 0 4px;
display: flex;
justify-content: center;
}
.column {
flex: 25%;
max-width: 25%;
padding: 0 4px;
}
.column img {
margin-top: 8px;
vertical-align: middle;
width: 100%;
}
#media screen and (max-width: 800px) {
.column {
flex: 50%;
max-width: 50%;
}
}
#media screen and (max-width: 600px) {
.column {
flex: 100%;
max-width: 100%;
}
}
<table align="center">
<tr>
<td align="center">
<div class="row">
<div class="column">
<img src="pics/photos/sample1.png">
<img src="pics/photos/sample2.png">
<img src="pics/photos/sample3.png">
</div>
<div class="column">
<img src="pics/photos/sample4.png">
<img src="pics/photos/sample5.png">
<img src="pics/photos/sample6.png">
</div>
<div class="column">
<img src="pics/photos/sample7.png">
<img src="pics/photos/sample8.png">
<img src="pics/photos/sample9.png">
</div>
</div>
</td>
</tr>
</table>
I am trying to create flexbox with different image heights and width. I want the break points as
max-width: 640px; ------->Only one column
max-width: 860px; -------->Two columns only
greater than: 860px;-------->Three column only
What I am messing with? Why it is becoming ugly while shrinking window?I am losing 3 column of image even before window size reach 860px breakpoint. What else can I do?
After window size reaches to 860px it is working fine, but until than it is becoming ugly.
I want my image height not be changed. Let it be as it is !
.container {
width: 100%;
height: 1000px;
display: flex;
flex-direction: column;
background: green;
flex-wrap: wrap;
align-items: center;
align-content: center;
justify-content: flex-start;
}
.box {
width: 30%;
border: 2px solid red;
margin: 8px;
}
img {
width: 100%;
height: auto;
}
#media screen and (max-width: 860px) {
.container {
background-color: red;
height: 1100px;
}
.box {
width: 46%;
}
}
#media screen and (max-width: 640px){
.container {
background-color: yellowgreen;
height: auto;
flex-direction: row;
}
.box {
width: 100%;
}
}
<div class="container">
<div class="box">
<img src="https://www.daily-sun.com/assets/news_images/2017/01/12/DAILYSUN_ZYAN.jpg" alt="">
</div>
<div class="box">
<img src="https://i.pinimg.com/originals/79/e2/8d/79e28db17abc2eb6c3085c9c72bff5e4.jpg" alt="">
</div>
<div class="box">
<img src="https://www.pinkvilla.com/files/styles/gallery-section/public/zayn_malik_tattoos_1.jpg?itok=Q5bXGlfm" alt="">
</div>
<div class="box">
<img src="https://i.pinimg.com/originals/b5/0c/30/b50c30ddaaffc98ff2cb077cc7f57823.jpg" alt="">
</div>
<div class="box">
<img src="https://images.news18.com/ibnlive/uploads/2021/01/1610783227_zayn-malik.jpg" alt="">
</div>
<div class="box">
<img src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/gigi-hadid-and-zayn-malik-attend-the-manus-x-machina-news-photo-527409630-1554477973.jpg?crop=1.00xw:0.762xh;0,0.0194xh&resize=480:*" alt="">
</div>
</div>
In this cas, I would use CSS column-count and CSS grid.
Just an example with your code:
.container {
column-count: 3;
column-gap: 10px;
background: green;
padding: 10px;
}
#media (max-width: 640px) {
.container {
column-count: 1;
}
}
#media (min-width: 641px) and (max-width: 840px) {
.container {
column-count: 2;
}
}
img {
max-width: 100%;
display: block;
}
.box {
margin: 0;
display: grid;
grid-template-rows: 1fr auto;
margin-bottom: 10px;
break-inside: avoid;
border: 2px solid red;
}
<div class="container">
<div class="box">
<img src="https://www.daily-sun.com/assets/news_images/2017/01/12/DAILYSUN_ZYAN.jpg" alt="">
</div>
<div class="box">
<img src="https://i.pinimg.com/originals/79/e2/8d/79e28db17abc2eb6c3085c9c72bff5e4.jpg" alt="">
</div>
<div class="box">
<img src="https://www.pinkvilla.com/files/styles/gallery-section/public/zayn_malik_tattoos_1.jpg?itok=Q5bXGlfm" alt="">
</div>
<div class="box">
<img src="https://i.pinimg.com/originals/b5/0c/30/b50c30ddaaffc98ff2cb077cc7f57823.jpg" alt="">
</div>
<div class="box">
<img src="https://images.news18.com/ibnlive/uploads/2021/01/1610783227_zayn-malik.jpg" alt="">
</div>
<div class="box">
<img src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/gigi-hadid-and-zayn-malik-attend-the-manus-x-machina-news-photo-527409630-1554477973.jpg?crop=1.00xw:0.762xh;0,0.0194xh&resize=480:*" alt="">
</div>
</div>
However for this layout using grid is the best way, but I tried to find a way by flex. For "flex-direction: column;" height is important so you should set a height that can't contain more than 2 images. I did it with "height: 70vw;"
.container {
width: 100%;
height: 70vw;
display: flex;
flex-direction: column;
background: green;
flex-wrap: wrap;
align-items: center;
align-content: center;
justify-content: flex-start;
}
.box {
width: 30%;
border: 2px solid red;
margin: 8px;
}
img {
width: 100%;
height: auto;
}
#media screen and (max-width: 860px) {
.container {
background-color: red;
height: 1120px;
}
.box {
width: 46%;
}
}
#media screen and (max-width: 640px){
.container {
background-color: yellowgreen;
height: auto;
flex-direction: row;
}
.box {
width: 100%;
}
}
<div class="container">
<div class="box">
<img src="https://www.daily-sun.com/assets/news_images/2017/01/12/DAILYSUN_ZYAN.jpg" alt="">
</div>
<div class="box">
<img src="https://i.pinimg.com/originals/79/e2/8d/79e28db17abc2eb6c3085c9c72bff5e4.jpg" alt="">
</div>
<div class="box">
<img src="https://www.pinkvilla.com/files/styles/gallery-section/public/zayn_malik_tattoos_1.jpg?itok=Q5bXGlfm" alt="">
</div>
<div class="box">
<img src="https://i.pinimg.com/originals/b5/0c/30/b50c30ddaaffc98ff2cb077cc7f57823.jpg" alt="">
</div>
<div class="box">
<img src="https://images.news18.com/ibnlive/uploads/2021/01/1610783227_zayn-malik.jpg" alt="">
</div>
<div class="box">
<img src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/gigi-hadid-and-zayn-malik-attend-the-manus-x-machina-news-photo-527409630-1554477973.jpg?crop=1.00xw:0.762xh;0,0.0194xh&resize=480:*" alt="">
</div>
</div>
I have 12 gallery thumbnails. How do I specify 4 media queries allowing only 6, 4, 3, or 2 columns while maintaining proportionate image scaling and equal margins at 10px between each thumbnail without causing the media query column rule to break? for example at min-width: 1000px it currently displays 5 columns instead of 6
<main class="gallery">
<img src="https://cdn0.wideopenpets.com/wp-content/uploads/2015/12/snake-in-hats-11feature-image-770x405.png" alt="" class="ctrl" id="btn-1">
<img src="https://i2.wp.com/metro.co.uk/wp-content/uploads/2015/11/party-snake.jpg?quality=90&strip=all&zoom=1&resize=644%2C427&ssl=1" alt="" class="ctrl" id="btn-6">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQk4j0EKreALTRlYkyIP8kLHfjY-1FcxUuyzjlv3pu2Uh_cdlu1&s" alt="" class="ctrl" id="btn-2">
<img src="https://ball-pythons.net/forums/cache2.php?img=https://41.media.tumblr.com/7f75b21e7edcc2adc45e4eb2f82a362a/tumblr_o52rt6NTRH1s9amz4o7_1280.jpg" alt="" class="ctrl" id="btn-7">
<img src="https://static.boredpanda.com/blog/wp-content/uploads/2015/11/cute-snakes-wear-hats-110__700.jpg" alt="" class="ctrl" id="btn-3">
<img src="https://www.thesun.co.uk/wp-content/uploads/2019/08/NINTCHDBPICT000516637716.jpg" alt="" class="ctrl" id="btn-8">
<img src="https://cdn0.wideopenpets.com/wp-content/uploads/2015/12/snake-in-hats-11feature-image-770x405.png" alt="" class="ctrl" id="btn-4">
<img src="https://i2.wp.com/metro.co.uk/wp-content/uploads/2015/11/party-snake.jpg?quality=90&strip=all&zoom=1&resize=644%2C427&ssl=1" alt="" class="ctrl" id="btn-9">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQk4j0EKreALTRlYkyIP8kLHfjY-1FcxUuyzjlv3pu2Uh_cdlu1&s" alt="" class="ctrl" id="btn-5">
<img src="https://ball-pythons.net/forums/cache2.php?img=https://41.media.tumblr.com/7f75b21e7edcc2adc45e4eb2f82a362a/tumblr_o52rt6NTRH1s9amz4o7_1280.jpg" alt="" class="ctrl" id="btn-10">
<img src="https://static.boredpanda.com/blog/wp-content/uploads/2015/11/cute-snakes-wear-hats-110__700.jpg" alt="" class="ctrl" id="btn-11">
<img src="https://www.thesun.co.uk/wp-content/uploads/2019/08/NINTCHDBPICT000516637716.jpg" alt="" class="ctrl" id="btn-12">
.gallery{
background: white;
width: 100%;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr) );
grid-gap: 10px;
align-items: start;
justify-items: center;
margin: auto;
padding: 40px 40px 40px;}
img {
background: lightblue;
box-shadow: none;
border-radius: 5px;
width:15vw;
height:10vw;
max-width: 100%;
}
.ctrl:active{
box-shadow: 0em 0em .5em rgba(0,0,0,0.75);
}
.ctrl:hover{
box-shadow: 0em 0em .5em rgba(0,0,0,0.75);
}
.ctrl:focus{
box-shadow: 0em 0em .5em rgba(0,0,0,0.75);
}
#media screen and (max-width : 505px ) {
.grid {
display: flex;
flex-wrap: wrap;
flex-direction: row;}
.cell {
width: 50%;
margin: 10px 10px 10px 10px;}}
#media ( min-width : 505px ) and (max-width : 800px ) {
.grid {
display: flex;
flex-wrap: wrap;
flex-direction: row; }
.cell {
width: calc(100% / 3);
margin: 10px 10px 10px 10px;
}
}
#media (min-width : 800px ) and ( max-width : 1000px) {
.grid {
display: flex;
flex-wrap: wrap;
flex-direction: row;
}
.cell {
width: calc(100% / 4);
margin: 10px 10px 10px 10px;} }
#media screen and (min-width: 1000px) {
.grid {
display: flex;
flex-wrap: wrap;
flex-direction: row;}
.cell {
width: calc(100% / 6);
margin: 10px 10px 10px 10px;}}
Yep flexbox to the rescue, hat tip to Nikk Pearce's codepen, which I then edited to fit your situation. Add spacing between elements and styling as needed from here.
* {
box-sizing: border-box;
}
.container {
margin: auto;
max-width: 1200px;
}
.responsive-image {
max-width: 100%;
}
.cell img {
display: block;
}
#media screen and (min-width: 600px) {
.grid {
display: flex;
flex-wrap: wrap;
flex-direction: row;
}
.cell {
width: 50%;
padding: 1em;
}
}
#media screen and (min-width: 1000px) {
.cell {
width: calc(100% / 4);
}
}
<div class="container">
<div class="grid">
<div class="cell">
<img src="http://placehold.it/800x800" class="responsive-image">
</div>
<div class="cell">
<img src="http://placehold.it/800x800" class="responsive-image">
</div>
<div class="cell">
<img src="http://placehold.it/800x800" class="responsive-image">
</div>
<div class="cell">
<img src="http://placehold.it/800x800" class="responsive-image">
</div>
<div class="cell">
<img src="http://placehold.it/800x800" class="responsive-image">
</div>
<div class="cell">
<img src="http://placehold.it/800x800" class="responsive-image">
</div>
<div class="cell">
<img src="http://placehold.it/800x800" class="responsive-image">
</div>
<div class="cell">
<img src="http://placehold.it/800x800" class="responsive-image">
</div>
<div class="cell">
<img src="http://placehold.it/800x800" class="responsive-image">
</div>
<div class="cell">
<img src="http://placehold.it/800x800" class="responsive-image">
</div>
<div class="cell">
<img src="http://placehold.it/800x800" class="responsive-image">
</div>
<div class="cell">
<img src="http://placehold.it/800x800" class="responsive-image">
</div>
</div>
</div>
I have this CSS grid setup which works perfectly, it displays 6 columns when viewed on a desktop and collapses to 1 when viewed on a mobile device.
However, I'd like it to collapse to 2 columns rather than 1 when viewed on a mobile device, I can't work out what I have to change to do this.
/* SECTIONS */
.section {
clear: both;
padding: 0px;
margin: 0px;
text-align: center;
}
/* COLUMN SETUP */
.col {
display: block;
float:left;
margin: 1% 0 1% 1.6%;
}
.col:first-child { margin-left: 0; }
/* GROUPING */
.group:before,
.group:after { content:""; display:table; }
.group:after { clear:both;}
.group { zoom:1; /* For IE 6/7 */ }
//* GRID OF SIX */
.span_6_of_6 {
width: 100%;
}
.span_5_of_6 {
width: 83.06%;
}
.span_4_of_6 {
width: 66.13%;
}
.span_3_of_6 {
width: 49.2%;
}
.span_2_of_6 {
width: 32.26%;
}
.span_1_of_6 {
width: 15.33%;
}
/* GO FULL WIDTH BELOW 480 PIXELS */
#media only screen and (max-width: 480px) {
.col { margin: 1% 0 1% 0%; }
.span_1_of_6, .span_2_of_6, .span_3_of_6, .span_4_of_6, .span_5_of_6, .span_6_of_6 { width: 100%; }
}
<div class="section group">
<div class="col span_1_of_6">
<span style="font-size:35px;"><i class="fas fa-wifi"></i></span><br />Wifi
</div>
<div class="col span_1_of_6">
<span style="font-size:35px;"><i class="fas fa-tv"></i></span><br />Smart TV With Freeview
</div>
<div class="col span_1_of_6">
<img width="75px" src="https://www.stickpng.com/assets/images/580b57fcd9996e24bc43c529.png"></img><br />Netflix
</div>
<div class="col span_1_of_6">
<img width="75px" src="https://www.stickpng.com/assets/images/580b57fcd9996e24bc43c548.png"></img><br />YouTube
</div>
<div class="col span_1_of_6">
<img width="50px" src="https://image.flaticon.com/icons/svg/2047/2047381.svg"></img><br />Towels
</div>
<div class="col span_1_of_6">
<img width="50px" src="https://image.flaticon.com/icons/svg/125/125669.svg"></img><br />Hair Dryer
</div>
</div>
Actually using CSS Grid
/* SECTIONS */
.section {
padding: 0px;
margin: 0px;
text-align: center;
display: grid;
/*6 Colum Grid*/
grid-template-columns: repeat(6, 1fr);
}
/* GO Two Colum BELOW 480 PIXELS */
#media only screen and (max-width: 480px) {
.section {
grid-template-columns: repeat(2, 1fr);
}
}
<div class="section group">
<div class="col span_1_of_6">
<span style="font-size:35px;"><i class="fas fa-wifi"></i></span><br />Wifi
</div>
<div class="col span_1_of_6">
<span style="font-size:35px;"><i class="fas fa-tv"></i></span><br />Smart TV With Freeview
</div>
<div class="col span_1_of_6">
<img width="75px" src="https://www.stickpng.com/assets/images/580b57fcd9996e24bc43c529.png"><br />Netflix
</div>
<div class="col span_1_of_6">
<img width="75px" src="https://www.stickpng.com/assets/images/580b57fcd9996e24bc43c548.png"><br />YouTube
</div>
<div class="col span_1_of_6">
<img width="50px" src="https://image.flaticon.com/icons/svg/2047/2047381.svg"><br />Towels
</div>
<div class="col span_1_of_6">
<img width="50px" src="https://image.flaticon.com/icons/svg/125/125669.svg"><br />Hair Dryer
</div>
</div>
width: 50% should do the trick https://jsfiddle.net/x52z9hk6/
/* GO FULL WIDTH BELOW 480 PIXELS */
#media only screen and (max-width: 480px) {
.col { margin: 1% 0 1% 0%; }
.span_1_of_6, .span_2_of_6, .span_3_of_6, .span_4_of_6, .span_5_of_6, .span_6_of_6 { width: 50%; }
}
media tag is triggered when 480px limit is reached, width: 100% makes it full row, width: 50% - half and so on
I have been trying to make a responsive auto rescaling image grid to display ads on our website. I used this as a reference - W3Schools-ImageGridMaker
Based on that, I tried 4days to come up with this piece of code.
div.gallery {
border: 1px solid #ccc;
}
div.gallery:hover {
border: 1px solid #777;
}
div.gallery img {
display: block;
object-fit: contain;
max-width: 100%;
max-height: 100%;
width: auto;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
}
* {
box-sizing: border-box;
}
.responsive {
padding: 0 6px;
float: left;
width: 24.99999%;
}
#media only screen and (max-width: 700px) {
.responsive {
width: 49.99999%;
margin: 6px 0;
}
}
#media only screen and (max-width: 500px) {
.responsive {
width: 100%;
}
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
div.boxed {
border: 5px solid red;
width: 100%;
height: auto;
overflow: auto;
}
<div class="boxed">
<div class="responsive">
<div class="gallery">
<a target="_blank" href="https://tnilive.com" onclick="window.open('https://www.google.com'); window.open('https://www.yahoo.com');"> <img src="https://i.imgur.com/UgPbxk2.jpg" alt="Shiva1"></a>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="https://tnilive.com" onclick="window.open('https://www.google.com'); window.open('https://www.yahoo.com');"> <img src="https://i.imgur.com/ColLeDr.png" alt="Shiva2"></a>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="https://tnilive.com" onclick="window.open('https://www.google.com'); window.open('https://www.yahoo.com');"> <img src="https://i.imgur.com/gVjcLg2.jpg" alt="Shiva3"></a>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="https://tnilive.com" onclick="window.open('https://www.google.com'); window.open('https://www.yahoo.com');"> <img src="https://i.imgur.com/nxGxovl.png" alt="Shiva4"></a>
</div>
</div>
</div>
This code is responsive, and on mobiles I got no problem because it looks neat by filling the full area. But if you look at it on a desktop, it injects empty space underneath some pics that doesn't fit the height. I am using bunch of URLs and can feed them as a list so that this 1280X200px area on desktop fills up neat with images that are of different sizes. I tried looking into freewall and a ton of other jsfiddles and pens but couldn't achieve on how to make the whitespace removed and make that particular box look good. Thanks.
Per my comments - I would go with a flexbox solution that uses object-fit (with a polyfil for ie):
.container {
display: flex;
flex-direction: row; /* default value so optional - lines children in a row */
flex-wrap: wrap; /* allows children to wrap */
justify-content: space-between; /* space children evenly over row */
}
.responsive {
flex-basis: 25%; /* makes the width 25% */
/* if you don't want a fixed height image, I would use the padding top trick for aspect ratio divs */
position: relative;
padding-top: 30%;
}
.responsive img {
position:absolute;
display: block;
width: 100%;
height: 100%;
top:0;
left:0;
object-fit:cover;
}
#media only screen and (max-width: 700px) {
.responsive {
flex-basis: 50%;
margin: 6px 0;
}
}
#media only screen and (max-width: 500px) {
.responsive {
flex-basis: 100%;
padding-top: 50%;
}
}
<div class="container">
<div class="responsive">
<div class="gallery">
<a target="_blank" href="https://tnilive.com" onclick="window.open('https://www.google.com'); window.open('https://www.yahoo.com');"><img src="https://www.fillmurray.com/400/600" alt="Shiva3"></a>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="https://tnilive.com" onclick="window.open('https://www.google.com'); window.open('https://www.yahoo.com');"><img src="https://www.fillmurray.com/400/400" alt="Shiva3"></a>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="https://tnilive.com" onclick="window.open('https://www.google.com'); window.open('https://www.yahoo.com');"><img src="https://www.fillmurray.com/400/900" alt="Shiva3"></a>
</div>
</div>
<div class="responsive">
<div class="gallery">
<a target="_blank" href="https://tnilive.com" onclick="window.open('https://www.google.com'); window.open('https://www.yahoo.com');"><img src="https://www.fillmurray.com/400/700" alt="Shiva3"></a>
</div>
</div>
</div>