The Cascading of Bootstrap Card Designs

Looking for some assistance with my TV Show Searcher project that is based on an API. The functionality is complete, but I'm struggling to get the Bootstrap cards to stack neatly without any empty space between them. I want it to resemble the image gallery layout of unsplash.com where images stack seamlessly regardless of size. Any help or advice would be greatly appreciated.

View Image Here

I have a single row div in which I dynamically add col-4 divs using JavaScript to display 4 TV shows per line based on the API data. Below are the HTML, CSS, and JS files containing the code snippet:

console.log('Connected')
const form = document.querySelector('#searchForm');
const imgs = document.querySelector('#imgsDisplay')
const search = document.querySelector('#searchDisplay')
const row = document.querySelector('#row')

form.addEventListener('submit',async function (e) {
    e.preventDefault();
    row.innerHTML='';
    const searchTerm = form.elements.query.value;
    const config = { params: { q: searchTerm } }
    const res = await axios.get(`http://api.tvmaze.com/search/shows`, config);
    search.textContent = form.elements.query.value
    makeImages(res.data)
    form.elements.query.value = '';
    
})


const makeImages = (shows) => {
    
    for (let result of shows) {
        if (result.show.image) {
            const col = document.createElement('div')
            col.classList.add('col-3', 'h-100')

            const imgDiv = document.createElement('div')
            imgDiv.classList.add('card', 'cardStyle', 'm-0')

            const img = document.createElement('IMG');
            img.classList.add('card-img-top')
            img.src = result.show.image.medium;


            const label = document.createElement('h5')
            label.textContent = result.show.name;
            label.classList.add("card-title")

            const text = document.createElement('p')
            text.classList.add('card-text')
            text.innerHTML = result.show.summary;

            const cardBody = document.createElement('div')
            cardBody.classList.add('card-body')

            const showSite = document.createElement('a')
            showSite.href = result.show.officialSite;
            showSite.textContent = 'Official Website'
            showSite.classList.add('btn', 'btn-outline-success')

            cardBody.append(label)
            cardBody.append(text);
            cardBody.append(showSite)

            imgDiv.append(img);
            imgDiv.append(cardBody);
            col.append(imgDiv);
            row.append(col);
            imgs.append(row);
        }
    }
}
#searchForm{
    width: 40%;
}

.cardStyle{
    width: 18rem;
}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TV Show Search</title>
    <link rel="stylesheet" href="app.css">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>

</head>

<body>

    <section>
        <div class="container d-flex flex-column align-items-center">
            <h1 class="display-1">TV Show Search</h1>
            <form id="searchForm">
                <div id="inputForm" class="container input-group mb-3">
                        <input id="search" type="text" class="form-control" placeholder="TV Show Title" aria-label="TV Show Title" aria-describedby="button-addon2" name="query">
                        <button class="btn btn-outline-success" id="button-addon2">Search</button>
                </div>
            </form>
            
        </div>
    </section>
    
    <section>
        <div class="container ms-1 mt-5">
            <h1 id='resultsHeader' class="display-3">Results for: <b><span id="searchDisplay"></span></b></h1>
        </div>
    </section>

    <section id="imgsDisplay" class="container mt-5">
        <div id = "row" class="row d-flex">

        </div>
    </section>
  
    
    <script src="app.js"></script>
</body>

</html>

Answer №1

To ensure your cards have the same height, apply overflow:hidden and a fixed height. This will prevent any extra text from causing display issues.

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

Sneak beneath another element with a div's sliding movement

I'm attempting to make an absolutely positioned div element (#slideout) slide underneath another div element .menu using CSS, if possible. Check out my code here. Currently, when the red tab is clicked, #slideout covers .menu, but I want it to hide ...

When trying to convert a function component to a class component, using `npm init react-app` may result in the error `ReferenceError: React is not defined no-undef`

After running npm init react-app appname, I noticed that the file App.js was created, containing a function component: function App() { return ( <SomeJSX /> ); } I decided to change this function component into a class component like this: c ...

Different option for positioning elements in CSS besides using the float

I am currently working on developing a new application that involves serializing the topbar and sidebar and surrounding them with a form tag, while displaying the sidebar and results side by side. My initial attempt involved using flex layout, but I have ...

What is the mechanism for invoking functions defined with the arrow syntax in Angular?

Referencing this code snippet from the tutorial at https://angular.io/tutorial/toh-pt4, specifically within the hero.component.ts file: getHeroes(): void { this.heroService.getHeroes() .subscribe(heroes => this.heroes = heroes); } After analyz ...

Using PHP with Slim PHP Framework to dynamically include CSS files in the header of a document

I have developed a sleek application featuring a login form, dashboard, registration page, and account page. Each of these pages has its own unique route. To maintain consistency across all pages, I have included a shared header and footer by inserting < ...

In order to work with the optionSelectionChanges property of the MdSelect directive in Angular Material2, it

Within my application, there is a Material2 select dropdown widget containing several options. app.component.html <md-select placeholder="Choose an option" [(ngModel)]="myOption" (optionSelectionChanges)="setOptionValue(myOption)"> &l ...

Adding a task to my database successfully through Postman integration

I'm having trouble implementing the code for my todo app using React. I am encountering an issue with adding a new todo to the database using the handleSubmit function. Oddly enough, it works fine when testing with Postman, but not when trying to inpu ...

Include personalized headers to the 'request'

I have configured my express server to proxy my API using the following setup: // Proxy api calls app.use('/api', function (req, res) { let url = config.API_HOST + req.url req.pipe(request(url)).pipe(res) }) In this instance, confi ...

What is causing my grayscale function to only impact part of the canvas?

As a beginner programmer, I have been experimenting with creating a grayscale function in JavaScript for practice. This is the code I have come up with: <canvas width='400' height='400'></canvas> <script> var can ...

Unable to load the node modules

In my development journey, I created an ASP.NET MVC project using Angular 2 in Visual Studio 2017 and set up node for package management. Here is a snippet from the package.json file: { "version": "1.0.0", "name": "asp.net", "private": true, ... ...

Is it possible to time a page without relying on the Form tag?

As I search for solutions, I have come across some examples that require a Form tag, but unfortunately, it doesn't seem to integrate well with my current application. My goal is to implement a timer on a webpage that starts counting when one button i ...

Clickable regions in Internet Explorer 7 that lack a specific width

Is there a way to make the clickable area of links always stretch to the parents container when the parent container does not have a fixed width? For example, check out this JSFiddle. In Firefox, the link stretches with the text and the li tag, but in IE ...

Repeatedly iterates through the JSON properties that have been grouped together

https://jsfiddle.net/MauroBros/f1j0qepm/28/#&togetherjs=qedN5gf7SF Upon examining a JSON object, the structure is as follows: var values = [ {"aname":"account1", "pname":"pname1", "vname":"vname1& ...

Issue with parameter functionality not working as expected

This code snippet is not functioning as expected. I am trying to extract and print the values from the URL parameter file:///C:/Users/laddi/Desktop/new%201.html?t=vindu&b=thind function GetURLParameterValue(param) { var pageURL = window. ...

What causes the values to constantly change whenever I insert an element into the array?

When I add an element, it automatically replaces all the others. This issue only occurs when I insert the entire object; if I insert a typical element such as an integer or a string, it works without any problems. <body> <div id="app&quo ...

What is the best way to incorporate code into a page with numerous conflicting CSS styles, without resorting to Scoped CSS?

Struggling to incorporate tab code into a page with conflicting CSS? Even after attempts to edit classes and labels, the original code fights back against the new additions. While scoped CSS seems like the perfect fix, it's not widely supported yet. ...

Ensure the http request is finished before loading the template

When my template loads first, the http request is fired. Because of this, when I load the page for the first time, it shows a 404 image src not found error in the console. However, after a few milliseconds, the data successfully loads. After researching a ...

What is the process of redefining the toString method for a function?

I am currently tackling a coding challenge that involves chaining functions. While researching possible solutions online, I noticed that many of them involved using function.toString and overriding the toString method of a function to create a chained add ...

Why am I seeing back-end console errors that are related to my front-end?

Recently, I encountered an error message that prevents me from using 'import' in my front end code when trying to execute 'node index'. This issue never occurred before, and it only arose when I returned to this project. In my backend ...

What could be causing my SVG bezier curves to malfunction in Firefox?

Encountered an issue today where diagrams I have generated are not functioning properly in Firefox when created using the getPointAtLength method. Here is a demonstration of the problem: http://jsfiddle.net/xfpDA/9/ Please take note of the comments at th ...