Using the card hover effect with the bootstrap modal causes issues

I am currently designing a webpage using bootstrap and EJS. I want to create a modal window when one button is clicked to show additional information, and when an X button or “close” button is pressed, the modal window is closed.
However, the transform effect inside the card:hover css effect is messing up the modal window.
For starters, here’s the rough code

<%- include('_header'); -%> << header includes Bootstrap css, js and Font Awesome css.
<style>
  /* Card Style */
  .card {
    border-radius: 15px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
  }
  .card:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.15);
  }
  .card-header {
    background-color: #007bff;
    color: white;
    border-top-left-radius: 15px;
    border-top-right-radius: 15px;
  }
  .badge-custom {
    font-size: 0.9em;
    padding: 8px 12px;
    border-radius: 20px;
  }
  /* Modal Style */
  .modal-header {
    border-bottom: 1px solid #dee2e6;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .modal-body {
    padding: 2rem;
  }
  .modal-footer {
    border-top: 1px solid #dee2e6;
    display: flex;
    align-items: center;
    justify-content: flex-end;
  }
  
</style>

...

<div class="container mt-5">

...

<div class="row">
    <div class="col-md-6 mb-4">
      <div class="card bg-light">
        <div class="card-header">
          <h5 class="card-title mb-0">고객</h5>
        </div>
        <div class="card-body">
          <ul class="list-group list-group-flush">
            <% project.consumers.forEach(consumer => { %>
              <li class="list-group-item bg-light">
                <i class="fas fa-user-tie me-2"></i>
                <%= consumer.name %>
                <button type="button" class="btn btn-link" data-bs-toggle="modal" data-bs-target="#consumerModal<%= consumer.id %>">
                  <i class="fas fa-info-circle"></i>
                </button>

                <!-- Modal Start -->
                <div class="modal fade" id="consumerModal<%= consumer.id %>" tabindex="-1" aria-labelledby="consumerModalLabel<%= consumer.id %>" aria-hidden="true">
                  <div class="modal-dialog">
                    <div class="modal-content">
                      <div class="modal-header">
                        <h5 class="modal-title" id="consumerModalLabel<%= consumer.id %>"><%= consumer.name %>의 상세 정보</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                      </div>
                      <div class="modal-body">
                        <% Object.entries(consumer.custom_attributes).forEach(([attrKey, attrValue]) => { %>
                          <p><strong><%= attrKey %>:</strong> <%= attrValue.content %></p>
                        <% }); %>
                      </div>
                      <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">닫기</button>
                      </div>
                    </div>
                  </div>
                </div>
                <!-- Modal End -->

              </li>
            <% }); %>
          </ul>
        </div>
      </div>
    </div>

...

</div>

So when I press the button below, a modal window should appear in the center of the screen.

                <button type="button" class="btn btn-link" data-bs-toggle="modal" data-bs-target="#consumerModal<%= consumer.id %>">
                  <i class="fas fa-info-circle"></i>
                </button>

However, the first results were as follows.

View post on imgur.com

As you can see in the image, a modal window appears in two places, and it flickers so fast that I can’t press the button. I asked ChatGPT to solve this problem and he recommended using the following JS to temporarily disable the transform.

<script>
  document.addEventListener('DOMContentLoaded', function () {
    var cards = document.querySelectorAll('.card');
    var modals = document.querySelectorAll('.modal');

    modals.forEach(function(modal) {
      modal.addEventListener('show.bs.modal', function () {
        cards.forEach(function(card) {
          card.style.transform = 'none';
        });
      });
      
      modal.addEventListener('hidden.bs.modal', function () {
        cards.forEach(function(card) {
          card.style.transform = '';
        });
      });
    });
  });
</script>

This eliminated the flickering modal window, but introduced another problem. The modal window would appear briefly in the div area that fetches the modal window, then disappear. Of course, many visitors will pass by without seeing this brief modal window, but I don’t think this is a good idea.

View post on imgur.com

transform: translateY(-5px);

In my code, if just one line above inside the CSS is missing, everything works fine.

View post on imgur.com

I would gladly give up the effect of the card moving slightly when the user hovers over the card component to avoid this complication. However, the current situation doesn’t make logical sense to me, and I need to know why it’s happening so I can move on to the next step. Why is this happening?

Attempted to inject Javascript, attempted to modify CSS.

New contributor

이융희 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật