aprl11
aprl11

Reputation: 53

CSS Border animation takes space inside table, rough animation when using position absolute

I'm trying to make a notification button with animation effect using border, but the animation is affecting the width and height of cell:

            .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>

What have I tried:

            .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>

This code should executedly fine by theory, though it's rough when it animates. Using position: absolute and fixed broke the entire notification's position.

I tried applying overflow:hidden or scroll, doesn't really do the job.

PS.

This is not a duplicate question, there are tons of questions related to this, but those related questions doesn't fix this problem (e.g. box-sizing: border-box).

Upvotes: 0

Views: 56

Answers (2)

traktor
traktor

Reputation: 19356

Wrapping the font-awsome <i> elements in an inline block container that prevents the animation from changing the position of other elements is a possible solution. This example uses a <span> wrapper with class .effect for this purpose:

.effect {
   overflow: visible;
   display: inline-block;
   width: 30px;
   text-align: center;
   height: 15px;
}
.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);
                }
            }
<!-- body-html -->
<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="effect"><i class="tooltips tooltip-notif fa fa-info-circle" style="" 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="effect"><i class="tooltips tooltip-notif fa fa-info-circle" style="" 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>

Upvotes: 1

Gulam Hussain
Gulam Hussain

Reputation: 1763

You are animating both border and margin properties, that's why it's expanding table cells.

I have made minor changes in your HTML and CSS to create a ripple effect. Hopefully, it will solve your problem.

.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>

Upvotes: 1

Related Questions