Comment highlight css transition effect

前端 未结 2 1675
感动是毒
感动是毒 2021-02-20 05:13

I\'m trying to accomplish the effect of when linking to a target element on another page, the target is highlighted and then fades to the default page color, aka white.

相关标签:
2条回答
  • 2021-02-20 05:32

    This is close to the effect you described

    :target {
      border-radius: 3px;
      animation: highlight 1000ms ease-out;
    }
    @keyframes highlight {
      0% {
        background-color: red;
      }
      100% {
        background-color: white;
      }
    }
    <div class="col-lg-12 section-header" id="additional">
      <h3>Required</h3>
    </div>
    
    <a href="#additional"> Click me </a>

    0 讨论(0)
  • 2021-02-20 05:42

    Use the :target pseudo-class to run a highlight animation.

    The :target CSS pseudo-class represents a unique element (the target element) with an id matching the URL's fragment.

    Clicking the link will change the URL's fragment identifier, so now the :target selector will point to the element with the matching id.

    :target {
      border-radius: 3px;
      animation: highlight 1000ms ease-out;
    }
    
    @keyframes highlight {
      from {
        background-color: red;
      }
    }
    <div class="col-lg-12 section-header" id="additional">
      <h3>Required</h3>
    </div>
    
    <a href="#additional"> Click me </a>

    0 讨论(0)
提交回复
热议问题