首页 > 解决方案 > CSS边框动画在表格内占用空间,使用绝对位置时的粗略动画

问题描述

我正在尝试使用边框制作具有动画效果的通知按钮,但动画正在影响单元格的宽度和高度:

            .tooltips {
                font-size: 11px;
                margin-top: -17px;
            }
            .tooltip-notif{
                animation: ripple 1s cubic-bezier(0, 0.2, 0.8, 1) infinite;
                border-radius: 49%;
            }
            @keyframes ripple {
                0% {
                    border: 0 solid black;
                }
                100% {
                    border: 10px solid rgba(0, 0, 0, 0);
                }
            }
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.9/css/all.css" integrity="sha384-5SOiIsAziJl6AWe0HWRKTXlfcSHKmYV4RBF18PPJ173Kzn7jzMyFuTtk8JA7QQG1" crossorigin="anonymous">
<table>
<tbody>
    <tr>
        <td style="display: none;" class="sorting_1">55</td>
        <td style="white-space: nowrap">Class F<i class="tooltips tooltip-notif fa fa-info-circle" style="" title="Click here to see some changes" data-title=""></i></td>
        <td style="display: none;">2021-06-10</td>
        <td style="display: none;">2021-06-21</td>
    </tr>
    
    <tr>
        <td style="display: none;" class="sorting_1">56</td>
        <td style="white-space: nowrap">Class C<i class="tooltips tooltip-notif fa fa-info-circle" style="" title="Click here to see some changes" data-title=""></i></td>
        <td style="display: none;">2021-06-10</td>
        <td style="display: none;">2021-06-21</td>
    </tr>
</tbody>
</table>

我尝试了什么:

            .tooltips {
                font-size: 11px;
                margin-top: -17px;
            }
            .tooltip-notif{
                animation: ripple 1s cubic-bezier(0, 0.2, 0.8, 1) infinite;
                border-radius: 49%;
            }
            @keyframes ripple {
                0% {
                    border: 0 solid black;
                    margin-top: 10px;
                    margin-left: 10px;
                }
                100% {
                    border: 10px solid rgba(0, 0, 0, 0);
                    margin-top: 0;
                    margin-left: 0;
                }
            }
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.9/css/all.css" integrity="sha384-5SOiIsAziJl6AWe0HWRKTXlfcSHKmYV4RBF18PPJ173Kzn7jzMyFuTtk8JA7QQG1" crossorigin="anonymous">
<table>
<tbody>
    <tr>
        <td style="display: none;" class="sorting_1">55</td>
        <td style="white-space: nowrap">Class F<i class="tooltips tooltip-notif fa fa-info-circle" style="" title="Click here to see some changes" data-title=""></i></td>
        <td style="display: none;">2021-06-10</td>
        <td style="display: none;">2021-06-21</td>
    </tr>
    
    <tr>
        <td style="display: none;" class="sorting_1">56</td>
        <td style="white-space: nowrap">Class C<i class="tooltips tooltip-notif fa fa-info-circle" style="" title="Click here to see some changes" data-title=""></i></td>
        <td style="display: none;">2021-06-10</td>
        <td style="display: none;">2021-06-21</td>
    </tr>
</tbody>
</table>

从理论上讲,这段代码应该执行得很好,尽管它在动画时很粗糙。使用position: absolutefixed破坏了整个通知的位置。

我尝试申请overflow:hiddenor scroll,并没有真正完成这项工作。

PS。

这不是一个重复的问题,有很多与此相关的问题,但这些相关问题并不能解决这个问题(例如box-sizing: border-box)。

标签: javascripthtmljquerycss

解决方案


您正在为bordermargin属性设置动画,这就是它扩展表格单元格的原因。

我对您的 HTML 和 CSS 进行了细微更改,以创建涟漪效果。希望它能解决您的问题。

.tooltip-notif {
    position: relative;
    border-radius: 49%;
  }

  .tooltip-notif {
    height: 30px;
    width: 30px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
  }
  .tooltip-notif::after {
    content: "";
    position: absolute;
    height: 50px;
    width: 50px;
    border-radius: 50%;
    transform-origin: center;
    background-color: black;
    animation: ripple 2s cubic-bezier(0, 0.2, 0.8, 1) infinite;
  }

  @keyframes ripple {
    0% {
      transform: scale(0);
      opacity: 0;
    }
    30% {
      opacity: 0.7;
    }
    100% {
      transform: scale(1);
      opacity: 0;
    }
  }
<link
  rel="stylesheet"
  href="https://use.fontawesome.com/releases/v5.0.9/css/all.css"
  integrity="sha384-5SOiIsAziJl6AWe0HWRKTXlfcSHKmYV4RBF18PPJ173Kzn7jzMyFuTtk8JA7QQG1"
  crossorigin="anonymous"
/>
<table>
  <tbody>
    <tr>
      <td style="display: none;" class="sorting_1">55</td>
      <td style="white-space: nowrap;">
        Class F<span class="tooltip-notif">
          <i
            class="tooltips fa fa-info-circle"
            title="Click here to see some changes"
            data-title=""
          ></i>
        </span>
      </td>
      <td style="display: none;">2021-06-10</td>
      <td style="display: none;">2021-06-21</td>
    </tr>

    <tr>
      <td style="display: none;" class="sorting_1">56</td>
      <td style="white-space: nowrap;">
        Class C
        <span class="tooltip-notif">
          <i
            class="tooltips fa fa-info-circle"
            title="Click here to see some changes"
            data-title=""
          ></i>
        </span>
      </td>
      <td style="display: none;">2021-06-10</td>
      <td style="display: none;">2021-06-21</td>
    </tr>
  </tbody>
</table>


推荐阅读