in Education by
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; } Run code snippetExpand snippet 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. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
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%; } }
Run code snippetExpand snippet

Related questions

0 votes
    I have a 9-cell grid containing images (using bootstrap columns). The grid works fine and is responsive ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I want to right align alternate list elements and keep the other left making it a ZIG-ZAG list Something ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I've extracted certain elements from a HTML page with beautifulsoup and want to extract the according CSS ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 3, 2022 in Education by JackTerrance
0 votes
    How can i wrap data in the table. Currently if template name is too long i get a scroll bar. I ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 19, 2022 in Education by JackTerrance
0 votes
    I am exploring Float Label pattern for web page using HTML and CSS. The code was referred from http: ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 27, 2022 in Education by JackTerrance
0 votes
    I have a polygon feature in OpenLayers 5. It has some random id which I need to show at the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    I use the vendor time picker component. Unfortunately, it uses rem units for most of its sizes, but ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    Why text inside / list is not affected (color of "item1", "item2" is not changed) by CSS applied ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    Why text inside / list is not affected (color of "item1", "item2" is not changed) by CSS applied ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 29, 2022 in Education by JackTerrance
0 votes
    Why text inside / list is not affected (color of "item1", "item2" is not changed) by CSS applied ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I would like to ask if I require a Mac for the entire process of the iPhone app development or ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    What is the difference between html and CSS?...
asked Dec 21, 2020 in Technology by JackTerrance
0 votes
    It is possible to convert the existing HTML, CSS websites to hybrid apps using PhoneGap. Please select the correct options from below (a)False (b)True...
asked Dec 11, 2020 in Education by Editorial Staff
0 votes
    I have some trouble to correctly embed images in html/php email. My .php file just sends out a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
...