bottom-border hover transition

后端 未结 1 1389
梦如初夏
梦如初夏 2020-12-11 14:17

Can any one tell me how to do a border-bottom hover effect from bottom to top?

\"enter

相关标签:
1条回答
  • 2020-12-11 14:35

    Here is a simple sample using the pseudo element ::after

    The advantage using this in favor of the border-bottom, it will not move the element up and down

    a {
      position: relative;
      padding: 10px 20px;
    }
    a::after {
      content: ' ';
      position: absolute;
      left: 0;
      bottom: -5px;
      width: 100%;
      height: 0;
      background: blue;
      transition: height 0.3s;
    }
    a:hover::after {
      height: 5px;
      transition: height 0.3s;
    }
    
    a + a::after {
      content: ' ';
      position: absolute;
      left: 0;
      bottom: -5px;
      width: 0;
      height: 5px;
      background: blue;
      transition: width 0.3s;
    }
    
    a + a:hover::after {
      width: 100%;
      transition: width 0.3s;
    }
    <a> Hover me </a> <a> Hover me 2 </a>

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