Modifying the image height in a column using Bootstrap and JSON data

My webpage is dynamically generating images from a JSON file through a JavaScript file. However, the images are displaying at different heights, and I want each column to adjust to the height of the image to eliminate any gaps. Particularly, data with the category "design" in the JSON file has a taller height compared to the category "website."

The HTML code is included in the JavaScript file because it needs to iterate over every data entry in the JSON.

$.getJSON('JSON/projects.json', function(data) {
        let projects = data.projects;
        let content = '';
        jQuery.fn.reverse = [].reverse;
        $.each(projects.reverse(), function(i, data) {
            if (data.category == category.toLowerCase()) {
                content += '<div class="col-md-6 mb-3" id="project-img"><a href="img/project/'+ data.img +'"data-lightbox="myproject" data-title="'+ data.caption +'"><img src="img/project/'+ data.img +'" alt="'+ data.caption +'" class="img-fluid"><br><br><a id="button2" href="'+ data.linkProject +'" target="_blank">Open This Project ></a><a id="button2" href="'+ data.linkDocumentation +'" target="_blank">Open Documentation ></a></a></div>';
            }
        });

        $('#project-list').html(content);
    });

I expect the columns to adjust to the height of the image so there are no gaps.

Answer №1

I believe you will enjoy this.

Code Snippet:

$.each(projects.reverse(), function(i, data) {
        if (data.category == category.toLowerCase()) {
            let contentItem = '<div class="img-container" id="project-img-'+ i +'"><a href="img/project/'+ data.img +'"data-lightbox="myproject" data-title="'+ data.caption +'"><img src="img/project/'+ data.img +'" alt="'+ data.caption +'" class="img-fluid"><br><br><a id="button2" href="'+ data.linkProject +'" target="_blank">Open This Project ></a><a id="button2" href="'+ data.linkDocumentation +'" target="_blank">Open Documentation ></a></a></div>';
            if (i % 2 == 0) {
              content = content + '<div class="images-wrapper">' + contentItem;
            } else {
              content = content + contentItem + '</div>';
            }
            
        }
    });

CSS Styles:

.img-container: {
    width: auth;
    height: 100%;
    vertical-align: middle;
}
.images-wrapper {
    display: flex;
    height: 300px;
    ...
}

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

Exploring Angular 2 - examining how @input is implemented within the ngOnInit lifecycle hook for testing a component

Presently, I am facing a challenge while attempting to test a child component that is designed to receive input from the host component and utilizes the ngOnInit lifecycle hook as depicted in the following code snippet. @Component({ selector: 'my ...

The external IP address cannot be accessed beyond the function scope in Node.js

Recently joining this community, I am in the process of retrieving my external IP through a package called "external-ip." The example code provided by them looks like this: const getIP = require('external-ip')(); getIP((err, ip) => { ...

Unable to disable indicators in Bootstrap 5 carousel; issue persists

My website has a carousel displaying 5 videos with navigation indicators at the bottom: <div class="col-lg-12 carousel slide" id="trailers" data-bs-ride="carousel" data-bs-ride="carousel"> <div class=&qu ...

Retrieving Values from Array with AngularJS Keys - A How-To Guide

I need to access a specific value from a key inside an array, like this: $scope.result = [ { "key":"logo_big", "value":"/assets/images/aaa.jpg" }, { "key":"logo_small", "value":"/assets/images/logo94x57Bis.png" }, { ...

Send an unchangeable list to a component that needs an Array

Just diving into the world of React and learning that using .toJS() is not recommended due to its impact on performance. The dilemma I'm facing is that a third-party component I'm using requires an array as props, while my state is stored as an ...

cycle through several handlebars entities

Hey friends, I could really use your help right now. I'm attempting to iterate through these objects using handlebars. RowDataPacket { idUser: 1, username: 'xxxxxx', password: 'xxxxx', fullname: 'Julian Rincon'}, RowDat ...

Pause autoplay in Bootstrap v5.0 Carousel when a carousel item is clicked

I've been attempting to disable the carousel autoplay using jQuery after clicking on a carousel item, but all my efforts have been unsuccessful. Can anyone provide some assistance? Thank you! This is what I've tried so far: $(".carousel-i ...

Clarifying the confusion surrounding AngularJS $q, promises, and assignments

Curious about a particular behavior I'm witnessing. Unsure if there's a misunderstanding on my part regarding promises, JavaScript, or Angular. Here's what's happening (I've prepared a plnkr to demonstrate - http://plnkr.co/edit/ZK ...

What is the method for displaying Facebook comments alongside the WordPress comments count?

I am currently using a template theme that initially had WordPress comments enabled on the website. By implementing the Facebook Comments plugin, I have successfully replaced Wordpress comments with Facebook Comments. **However, there seems to be an issue ...

Turning off the ability to horizontally scroll in an iframe using touch controls

I am trying to disable horizontal scrolling in an iframe on my website, particularly when a user uses touch input and drags horizontally. The scroll bars can still be visible and draggable when touched directly. Unfortunately, I do not have control over th ...

I am currently experiencing difficulties with uploading an image from the admin panel in Magento 1.9. Instead of receiving the expected response, I am

I encountered an error while trying to upload a file in Magento for a product image. When I click on upload, an error is displayed during the file upload process. Upon further investigation in the product.js file for item response, I noticed that HTML is b ...

Setting the position of a tooltip relative to an element using CSS/JS

I'm struggling to make something work and would appreciate your help. I have a nested list of items that includes simple hrefs as well as links that should trigger a copy-to-clipboard function and display a success message in a span element afterwards ...

Tips for changing the size and color of SVG images in a NextJS application

Looking to customize the color and size of an svg image named "headset.svg". Prior to this, I used next/image: <Image src={'/headset.svg'} alt='logo' width={30} height={30} className='object-contain' /> The s ...

Safely render user-generated HTML content within a React application to prevent cross-site scripting vulnerabilities

A unique situation has arisen in our React app where a user inputs a string that is displayed to other users. The challenge lies in searching for specific characters within the string and replacing them with HTML elements. For example, transforming the wor ...

Different ways of manipulating images with JavaScript

I attempted to tackle the issue independently, but I'm stumped. Is there a way to adjust the width of an image in JS when the screen dimensions are changed? ...

Getting the values of $scope variables from AngularJS in the controller to the view

I have a simple scope variable on my AngularJS Controller. It is assigned a specific endpoint value like this: $scope.isItAvailable = endpoint.IS_IT_AVAILABLE; How can I properly use it in my view (HTML) to conditionally show or hide an element using ng- ...

Exploring the capabilities of Laravel Webpack Mix and harnessing the power of the

I'm curious about integrating Laravel Webpack Mix with version 5.8 of Laravel. Do I have to include Vue/jQuery in app.js using the extract method in Webpack Mix? Will this result in duplication when loading manifest.js/vendor.js/app.js ? ...

Is there a way to center li elements evenly on mobile devices, regardless of the text length?

Take a look at these two images showcasing my website on different devices: Mobile: https://i.sstatic.net/spsYj.png Desktop: https://i.sstatic.net/AvFiN.png I have organized the content using simple ul and li tags. How can I adjust the layout so that ea ...

Designing a custom HTML calendar

I am currently working on a school project where I am creating a calendar using HTML. So far, I have set up the basic structure of the page. What I want to achieve is a functional calendar where users can create appointments that will be displayed accordi ...

Is there a way to adjust the width of my web layout without sacrificing its responsiveness?

Struggling with my website layout design as I encountered an issue. The overall width of the layout is too excessive, and I want to introduce some margins on the sides for a better visual appeal. Although the responsive design works well originally, adding ...