Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

98
Vistas
Javascript search bar displaying holes in place of not displayed cards

so I'm building this online learning website, and I have a catalog of all courses where you can search for courses which titles or description contain the input in the search bar. I used bootstrap cards to make the catalog. It's working well, but on desktop I get empty spaces in place of the cards which are hidden, and the results show with big empty spaces between them is there were courses in between etc. No issue on mobile, all results show up vertically one after another. Is there a way to go around that? thanks!

Picture to see the "empty spaces"

JS code:

$('#live_search').on('keyup', function() {
    let input = $(this).val();
    $('.card').hide();
    $('.card').filter(function() {
        return new RegExp(input, 'i').test($(this).text())
    }).show();
});

Cards:

<div class="search">
            <form>
                <label for="live_search">Rechercher une formation :</label>
                <input type="text" id="live_search" size="30" class="form-control" placeholder="Rechercher une formation" />
            </form>
        </div>
        <br>
            <div class="container px-5 mb-3">
                <div class="row">
                    {% for formation in formations %}
                        <div class="col-md-4">
                            <div class="card">
                                <img class="card-img-top" src="{{ vich_uploader_asset(formation, 'imageFile') }}" alt="{{ formation.imageName }}">
                                <div class="card-body">
                                    <h5 class="card-title">{{ formation.title }}</h5>
                                    <p class="card-text">{{ formation.description }}</p>
                                    <a class="small btn btn-success custom-btn rounded-pill px-3" href="{{path('app_formations_see', {'id' : formation.id })}}" role="button">voir</a>
                                    <span class="small">par {{ formation.user.firstname }} {{ formation.user.lastname }}</span>
                                </div>
                            </div>
                        </div>
                    {% endfor %}
                </div>
            </div>
about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You're hiding the card but keeping the col-md-4 div. You can merge the col-md-4 and card divs.

about 4 years ago · Santiago Trujillo Denunciar

0

Just hide the col-md-4 div by introducing a "wrapper" class (or whatever you want to call it)

JS Code

$('#live_search').on('keyup', function() {
    let input = $(this).val();
    $('.wrapper').hide();
    $('.wrapper').filter(function() {
        return new RegExp(input, 'i').test($(this).text())
    }).show();
});

Cards

<div class="search">
            <form>
                <label for="live_search">Rechercher une formation :</label>
                <input type="text" id="live_search" size="30" class="form-control" placeholder="Rechercher une formation" />
            </form>
        </div>
        <br>
            <div class="container px-5 mb-3">
                <div class="row">
                    {% for formation in formations %}
                        <div class="col-md-4 wrapper">
                            <div class="card">
                                <img class="card-img-top" src="{{ vich_uploader_asset(formation, 'imageFile') }}" alt="{{ formation.imageName }}">
                                <div class="card-body">
                                    <h5 class="card-title">{{ formation.title }}</h5>
                                    <p class="card-text">{{ formation.description }}</p>
                                    <a class="small btn btn-success custom-btn rounded-pill px-3" href="{{path('app_formations_see', {'id' : formation.id })}}" role="button">voir</a>
                                    <span class="small">par {{ formation.user.firstname }} {{ formation.user.lastname }}</span>
                                </div>
                            </div>
                        </div>
                    {% endfor %}
                </div>
            </div>
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda