Issue with Bootstrap cards overlapping while searching

On my Bootstrap 4 page, I've incorporated cards that can be searched, displaying only those with matching titles. However, I am facing two main issues. Firstly, when two matching cards are on the same row, they overlap. Secondly, if a matching card is on a different row, it does not move up to the first row. Despite trying various solutions, I have been unsuccessful in resolving these issues. I am seeking guidance on what steps I should take or where I should focus my efforts.

<html lang="en" dir="ltr">
  <head>
  ...
</body>
</html>
$(document).ready(function(){
  $('#search').on("keyup", function() {
    ...
  });
});
// Media queries for different screen sizes and custom CSS styles
.body{
  ...
}

.card{
  ...
}

.card-columns{
  ...
}

.card-body {
  ...
}

.card-deck{
  ...
}

.navbar{
  ...
}

.navbar-custom{
  ...
}

.container-fluid-nav{
  ...
}

.btn{
  ...
}

button.btn {
  ...
}

h2{
  ...
}

img {
  ...
}

.release-date{
  ...
}

.no-results{
  display: none;
}

Screenshot after search

Desired result

Link to JSFiddle Code

Answer №1

To enhance the functionality, ensure you add another CSS class named uvs to your column and apply the same in jQuery as shown below:

$(document).ready(function(){
  $('#search').on("keyup", function() {
    var value = $(this).val().toLowerCase();
    $(".uvs").filter(function() {
      $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
    });
  });
});
// CSS Media Queries
@media (max-width: 575.98px) { ... }
@media (max-width: 767.98px) { ... }
@media (max-width: 991.98px) { ... }
@media (max-width: 1199.98px) { ... }

// Additional CSS Styles
.body{
  margin-left:auto;
  margin-right:auto;
  position: static;
  z-index: 999;
}

.card{
  width: 40%;
  margin-top: 30px;
  margin-bottom: 50px;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
}

.card-columns{
  display: inline-block
}

/* More CSS Styles... */

.uvs{margin-bottom:30px;}
<html lang="en" dir="ltr">
  <head>
     <link rel="stylesheet" type="text/css" href="style.css">
    <script src="main.js"></script>
      </head>
<body>

    <div class="container-fluid-nav text-center">
       <h2>All the Cats</h2>
    </div>

     <div class="container">
         <input class="form-control" type="search" id="search" placeholder="Search" aria-label="Search">
      </div>

      <!-- Cards Section -->
      <div class="container">
        <div class="card-deck">
          <div class="row">
              <div class="col-lg-4 col-md-6 col-sm-12 uvs">
                  <div class="card h-100">
                    <div class="card-body">
                      <img src="cat-image.jpg" class="card-img-top" alt="...">
                      <h5 class="card-title text-center">Cute Cat</h5>
                      <p class="card-text text-center">Cat Name: Whiskers<br />Age: 2 years<br />Color: Gray</p>
                      <div class="mt-auto">
                        <a href="#" class="align-self-end btn btn-primary" target="_blank">Adopt</a>
                        <a href="#" class="align-self-end btn btn-secondary" disabled>Resell</a>
                      </div>
                    </div>
                  </div>
              </div>
              /* More cat cards... */
          </div>
          <div class="no-results">No cats found</div>
        </div>
      </div>

  </body>
</html>

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

What is the best way to position the menu along the right side of the container?

Apologies if this question seems trivial, but I have been struggling to find a solution for positioning my navigation bar on the right side of the container (prior to the order button). Despite hours of searching, I still haven't come across a viable ...

Adjust the CSS within a <style> element using jQuery or javascript

What I aim to accomplish: I intend to dynamically add and modify rules within a <style> tag using JavaScript/jQuery. Reason behind this goal: I am in the process of creating a color scheme editor where changes made by the user should be reflected ...

CSS Positioning: the container is not the right size for its content dimensions

Code Snippet: <div content> <div post> <div post> ... </div> Styling: .post { margin: 0; padding: 110px 20px 20px; float: left; width: 560px; position: relative; display: block; } #content { display ...

Error message: "Function is not defined"

Below is a snippet of my JavaScript code: $('td:eq(2)', nRow).html('<a class="critical" href="#" OnClick="toAjax(\''+aData[1]+'\', \''+aData[2]+'\');">'+aData[3]+'& ...

Reducing div size when clicked - Using JQuery version 1.9

I am looking to make a specific div shrink in size, while keeping all the data visible, each time a user clicks on a certain icon with the class legend-icon. For example, I want the div with the ID #Chart to shrink when clicked. This is the HTML code: &l ...

How can you attach an event handler to an HTML button without disrupting its default behavior?

I am working on enhancing a contact form to include a feature where the submit button becomes disabled for five seconds after it is clicked. This is to prevent accidental repeat submissions from occurring. However, I am facing an issue where disabling the ...

Having trouble adding your own styling to bootstrap-4 using a custom CSS file?

Here is the code I used to connect my two stylesheets, with the custom css file being linked second as per what I believe is the correct way to do it. <!doctype html> <html> <head> <link rel="stylesheet" type="text/css" href=" ...

Using a JSON file as a database for a project featuring HTML, CSS, and Vanilla JavaScript

Our task was to create a project that exclusively utilized JSON files for data storage. The data structure we were working with resembles the following: [ { "aircraftName": "Boeing 747", "departDate": 1640173020000, ...

Using @font-face with Rails version 2.3.8

Hello, I am having trouble including a custom font in my Rails application. I am currently using Rails 2.3.8. I have placed my font folder in the public folder and below is my CSS code. However, it seems to not be working. Can anyone provide some assistan ...

I encountered a difficulty when trying to update form data in MySQL utilizing PHP and jQuery

So here's the situation: I've managed to insert and delete records from a form using jQuery and PHP scripts to interact with a MYSQL database. However, I'm facing a challenge when it comes to updating data that has been retrieved from the da ...

The webpage failed to show the hamburger menu

I'm trying to create a hamburger menu and have written the following code: <header class="header"> <nav class="flex flex-jc-sb flex-ai-c"> <a href="/" class="header__logo"> <img src="im ...

Using Jquery to automatically adjust price based on selected options

Running an online retail store means you can offer products with different variables. For example: Colour: <select class="vars" name="size"> <option>Choose an option</option> <option data-price="-10.00" value="B">blue</o ...

How can I efficiently store and access DOM elements in my React application to avoid constant re-fetching?

Is there a known pattern for storing references to both regular DOM elements and jQuery elements within a class? Despite the general advice against using jQuery with React, I needed the jQuery functions for my menu to function properly and did not have ti ...

Unable to apply nativeElement.style.width property within ngOnChanges lifecycle method

My current task involves adjusting the width of containers while also monitoring changes in my @Input since the DOM structure is dependent on it. @Input('connections') public connections = []; @ViewChildren('containers', { read: Elemen ...

Need a tool for validating forms?

I am currently facing some confusion with the UI Validation plugin that we are using. Within our application, we employ Spring MVC, Jquery & Bootstrap. As we delve into UI development, we have encountered uncertainty in selecting an appropriate Validation ...

Identifying the presence of a mouse inside an element using jQuery

I am working on a website that utilizes jQuery. The structure of my page is as follows: <div id="page"> <!-- Content goes here --> <div id="content"> <div class="row"> <div class="col"><!-- content goes here ...

How to vertically center align h1 using Bootstrap

<body> <nav class="navbar navbar-expand-md bg-dark navbar-dark py-3"> <div class="container"> <div class="navbar-brand mx-auto"><h2 style="color: white;">Name< ...

The WebView.HitTestResult method is currently only receiving <img src> elements and not <a href> elements

I am attempting to open a new window in the Android browser using "_blank". I have set up an event listener for this purpose. mWebView.getSettings().setSupportMultipleWindows(true); mWebView.setWebChromeClient(new WebChromeClient() { ...

Rotate through different image sources using jQuery in a circular pattern

I'm working on a project where I have 3 img tags in my HTML file. My goal is to change the src of all 3 images with a button click, using an array that stores 9 different image src links. When the page initially loads, it should display the first set ...

Experiencing an issue while attempting to retrieve JSON data from an MVC Controller, with the error message of net::ERR_IN

I am attempting to retrieve JSON data from my controller for use in jQuery. The code I have written seems correct, as visiting the URL in my browser returns the JSON data, confirming that the controller is functioning properly. However, I encounter the fol ...