最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - unable to select top icon in a vertical stack using bootstrap - Stack Overflow

programmeradmin0浏览0评论

I'm trying to create selectable icons to initiate the sorting of a date column. I'm using Bootstrap 5 and font awesome icons. Visually, everything is fine.

<style>
    .sort-wrapper {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
    }

    .sort-wrapper i.fa{
      line-height: 0;
      margin: 0 auto;
    }

    .clickable {
      cursor: pointer;
      transition: transform 0.2s;
    }

    .clickable:hover {
      transform: scale(1.1);
    }
</style>

<div class="d-flex justify-content-start">
   Release Date
   <div class="sort-wrapper ms-3">
     <i id="ascending" class="fa fa-sort-up fa-lg clickable" ></i>
     <i id="descending" class="fa fa-sort-down fa-lg clickable" ></i>
   </div>
</div>

gives me

which is what I intended. However, when I throw in some jquery to trigger based on the selection ...

$('#ascending').click(function() {
  console.log("ascending");
});

$('#descending').click(function() {
  console.log("descending");
});

What I experience is that the "ascending" icon is never selectable. When I click on it I always get the "descending" message. I also noticed a strange behavior when I tried to add tooltips to the icons. The "descending" icon would behave properly, but not the "ascending" icon.

Is there some oddity associated with clickable items being too close to each other?

I'm trying to create selectable icons to initiate the sorting of a date column. I'm using Bootstrap 5 and font awesome icons. Visually, everything is fine.

<style>
    .sort-wrapper {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
    }

    .sort-wrapper i.fa{
      line-height: 0;
      margin: 0 auto;
    }

    .clickable {
      cursor: pointer;
      transition: transform 0.2s;
    }

    .clickable:hover {
      transform: scale(1.1);
    }
</style>

<div class="d-flex justify-content-start">
   Release Date
   <div class="sort-wrapper ms-3">
     <i id="ascending" class="fa fa-sort-up fa-lg clickable" ></i>
     <i id="descending" class="fa fa-sort-down fa-lg clickable" ></i>
   </div>
</div>

gives me

which is what I intended. However, when I throw in some jquery to trigger based on the selection ...

$('#ascending').click(function() {
  console.log("ascending");
});

$('#descending').click(function() {
  console.log("descending");
});

What I experience is that the "ascending" icon is never selectable. When I click on it I always get the "descending" message. I also noticed a strange behavior when I tried to add tooltips to the icons. The "descending" icon would behave properly, but not the "ascending" icon.

Is there some oddity associated with clickable items being too close to each other?

Share Improve this question asked Feb 3 at 21:48 Steve MaringSteve Maring 2051 gold badge4 silver badges11 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

My problem was that the descending font awesome icon was completely covering the ascending icon. I could see this clearly by adding the fa-border class and setting the line-height to 1.

发布评论

评论列表(0)

  1. 暂无评论