Get rid of any empty space in the image preview icon

Is there a way to eliminate the white space that appears when mixing landscape and portrait images? I want the images to move up and fill the space, even if they don't align perfectly.

Additionally, I would like the images to resize based on the scale of the browser window.

Here is the HTML code:

<?php
$dir = "img/";
$img = glob($dir . "*.jpg");

foreach ($img as $image) {
  echo "<img src='$image' class='imageCont'/>";
}
?>

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Photography</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" media="screen" href="main.css" />
</head>

<body>

</body>

</html>

And here is the CSS:

.imageCont {
  max-width: 200px;
  margin: 1px;
  transition: all 0.2s linear;
}

.imageCont:hover {
  transform: scale(1.1);
  box-shadow: 0px 0px 47px -2px #000000bf;
  transition: all 0.2s linear;
}

Answer â„–1

In order to shift the images upwards, it is necessary to align them properly. This can be achieved by using:

vertical-align:top;

To eliminate any extra space on the left or right side, you can utilize either:

float:left;

or

margin-left:-3px;

Keep in mind that if the heights of the rows differ, the images in the next row will align with the bottom of the tallest image from the previous row.

Answer â„–2

I discovered a new approach

<?php
$directory = "img/";
$imageList = glob($directory . "*.jpg");
?>

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Photography</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" media="screen" href="main.css" />
</head>

<body>

    <section class="imageCont">
        <?php foreach ($imageList as $pic) {echo "<img src='$pic' class='imageCont' style='max-width:200px' />";}?>
    </section>

    <script src="js/jquery.min.js"></script>
    <script src="js/main.js"></script>

</body>

</html>

CSS

.imageCont img {
  overflow: hidden;
  transition: all 0.2s linear;
  margin: 1px;
}

.imageCont img:hover {
  transform: scale(1.1);
  box-shadow: 0px 0px 47px -2px #000000bf;
  transition: all 0.2s linear;
}

.landscape {
  max-width: 200px;
  width: 100%;
  height: auto;
}

.portrait {
  max-height: 133px;
  width: auto;
  height: 100%;
}

JS

$(window).on('load', function () {
  $('.imageCont img').each(function () {
    if ($(this).width() / $(this).height() >= 1) {
      $(this).addClass('landscape');
    } else {
      $(this).addClass('portrait');
    }
  });
});

Sample

Answer â„–3

I've been making great progress with this solution, but I have encountered an issue with images not loading correctly at times. It seems like they stack on top of each other when loading.

Sample error

Here is the current code snippet:

HTML

<?php
$dir = "img/";
$img = glob($dir . "*.jpg");
?>

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title>Photography</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" media="screen" href="main.css" />
</head>

<body>

    <div class="grid">
        <div class="grid-sizer"></div>
        <?php foreach ($img as $image) {echo "<div class='grid-item'><img src='$image'></div>";}?>
    </div>

    <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script src="https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.js"></script>
    <script src="https://unpkg.com/imagesloaded@4/imagesloaded.pkgd.js"></script>
    <script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f48797869b9898869182919598b4c0dac4dac1">[email protected]</a>/dist/scrollreveal.js"></script>
    <script src="js/main.js"></script>

</body>

</html>

CSS

* {
  box-sizing: border-box;
}

.grid:after {
  content: '';
  display: block;
  clear: both;
}

.grid-sizer,
.grid-item {
  width: 33.333%;
}

.grid-item {
  float: left;
}

.grid-item img {
  display: block;
  max-width: 100%;
  transition: all 0.2s linear;
  padding: 5px 5px;
}

.grid-item img:hover {
  box-shadow: 0px 0px 40px -1px #000000bf;
  transition: all 0.2s linear;
}

JS

var $grid = $('.grid').masonry({
  percentPosition: true,
  columnWidth: '.grid-sizer',
  itemSelector: '.grid-item'
});

$grid.imagesLoaded().progress(function () {
  $grid.masonry();
});

ScrollReveal().reveal('.grid-item', {
  delay: 100,
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Comparing defaultProps with the logical OR operator

Being relatively new to react, I’ve adopted a method of defining default values which looks like this: class TextInput extends Component { render() { return ( <input type="text" name={ this.pr ...

Develop a Vue mixin to enable theme switching in a Vue.js application

I have successfully developed three distinct themes: light, default, and dark. Currently, I am working on implementing a toggle function in the footer section that allows users to switch between these themes effortlessly. Following the guidance provided b ...

"Exploring the concept of master pages in web development with the combination

Recently, I have been developing a website that functions similarly to olx, displaying ads based on the visitor's location (for example, showing Mumbai ads if the visitor is from Mumbai). Initially, I was planning to create separate pages for each cit ...

I have configured my CSS styles in the module.css file of my Next.js application, but unfortunately, they are not being applied

I recently developed a nextjs with electron template application: Here is the link to my code on CodeSandbox: https://codesandbox.io/s/sx6qfm In my code, I have defined CSS classes in VscodeLayout.module.css: .container { width: '100%'; he ...

Creating an IntersectionObserver with the Composition API: A Step-by-Step Guide

I am currently in the process of incorporating an IntersectionOberver that will update the url once the viewport transitions into a new section. I came across This thread and now endeavoring to apply it in vue 3 compositon api. The script is being integra ...

What could be causing the if statement to evaluate as false even though the div's style.display is set to 'block'?

Building a react application using createreactapp and encountering an issue with an if statement that checks the CSS display property of a div identified as step1: const step1 = document.getElementById("step-1") if (step1.style.display === 'blo ...

Encountering errors while attempting to share files in a system built with Node.js, Express,

This snippet shows my Node.js code for connecting to a database using Mongoose const mongoose = require('mongoose'); function connectDB() { // Establishing Database connection mongoose.connect(process see your Naughty's you're sure ...

What is the best way to display two radio buttons side by side in HTML?

Looking at my HTML form in this JSFiddle link, you'll see that when the PROCESS button is clicked, a form with two radio buttons appears. Currently, they are displayed vertically, with the female radio button appearing below the male radio button. I& ...

Diving into Symfony2's subform features

I am attempting to embed one form within another form without creating a class specifically for the forms. Here is my current approach: $form = $this ->buildForm('UserAlert', $alert) ->add('Alert', 'entity&a ...

Using HTML and CSS to implement a broadened perspective for a specific design

https://i.stack.imgur.com/ckQHa.png Hello, I am facing an issue with a UX design that is optimized for 1200px resolution width. However, when the HTML is loaded in a browser on a larger window resolution, there is a 200px gap on the right side. How can I ...

Can someone assist me with indicating the starting page to display in the controller?

My pagination setup appears as follows: //Controller (UserController) public show(){ $users = DB::table('user')->paginate(15); return view('user'); } public process(Request $request){ //perform update return $this ...

Organize images with overlays to the center of the page

I need help centering a group of pictures (a 3x3 table) on my webpage. I was able to center them before adding image overlays, but now the images are showing up in the top left corner of the page. How can I group and center them, and how do I specify the i ...

Incorporate a new CSS class into a DIV using JavaScript

Sample HTML: <div id="bar" class="style_one"></div> Is there a way to include the class style_two without deleting style_one? final outcome: <div id="bar" class="style_one style_two"></div> ...

Error message: "Unable to access D3 data when trying to select nested

Working with JSON data in D3 is proving to be a challenge for me. The file seems to be properly read, as indicated by its appearance when I use console.log, and it appears to be correctly formatted based on the examples I have come across. However, when I ...

Can you explain the concepts of 'theme' and 'classes'?

Currently, I am working on a web application using React. I have chosen to incorporate the latest version of Material-UI for designing the user interface. During this process, I came across the demo examples provided by Material-UI (like ) In each demo ...

Error: Module not found - Unable to locate 'dropzone'

Since migrating from Angular 4.4 to Angular 8.0, I encountered the following issue: ERROR in ./src/attributes/import/import.component.ts Module not found: Error: Can't resolve 'dropzone' in 'C:....\src\attributes\imp ...

Error in React Component: Array objects in response are not in correct order

My React app is receiving data via websocket, with a big object that contains game information. One of the properties is an array of player objects: { propertyX: "X", players: [{player1}, {player2}, {player3}], propertyY: "Y" } The issue I'm f ...

Using a <div> to contain <mat-card> in Angular Material

Can you achieve the following: Show components with specified width in a row instead of the usual column layout Enclose the cards within another defined container I've been attempting to accomplish this but without success so far.... While materia ...

steps to confirm the presence of a character within a string

$text = "#hello"; I want to extract the word hello from the string without the prefix #. Additionally, I need a function to check if the string includes the # symbol. str_replace("#", "", $text); and so does strpos($text,"#") Any suggestions? ...

Why does only the initial iteration of this loop seem to be functioning correctly?

It seems that only the initial iteration of my loop is being added to the array I had set up. for ($i=1; $i < 2; $i++) { $this->data['checks'] = array( 'ques'.$i => $this->input->post('questionNumber'.$ ...