【问题标题】:CSS underline animation - Reading directionCSS下划线动画 - 阅读方向
【发布时间】:2017-12-11 16:09:42
【问题描述】:

我找到了一个代码来为链接的下划线设置动画,但我想在另一个方向上,因为我们阅读(从左到右)实际上是相反的。这是JSFiddle

.sliding-u-l-r-l-inverse {
  display: inline-block;
  position: relative;
  padding-bottom: 3px;
}

.sliding-u-l-r-l-inverse:before {
  content: '';
  display: block;
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 100%;
  transition: width 0s ease;
}

.sliding-u-l-r-l-inverse:after {
  content: '';
  display: block;
  position: absolute;
  right: 0;
  bottom: 0;
  height: 3px;
  width: 100%;
  background: blue;
  transition: width .8s ease;
}

.sliding-u-l-r-l-inverse:hover:before {
  width: 0%;
  background: blue;
  transition: width .8s ease;
}

.sliding-u-l-r-l-inverse:hover:after {
  width: 0%;
  background: transparent;
  transition: width 0s ease;
}
<div class="sliding-u-l-r-l-inverse">
  I want it to slide on the other direction.
</div>

【问题讨论】:

    标签: css animation css-transitions underline


    【解决方案1】:

    .sliding-u-l-r-l-inverse {
      display: inline-block;
      position: relative;
      padding-bottom: 3px;
    }
    
    .sliding-u-l-r-l-inverse:before {
      content: '';
      display: block;
      position: absolute;
      right: 0;
      bottom: 0;
      height: 3px;
      width: 100%;
      transition: width 0s ease;
    }
    
    .sliding-u-l-r-l-inverse:after {
      content: '';
      display: block;
      position: absolute;
      left: 0; /* changed from 'right' */
      bottom: 0;
      height: 3px;
      width: 100%;
      background: blue;
      transition: width .8s ease;
    }
    
    .sliding-u-l-r-l-inverse:hover:before {
      width: 0%;
      background: blue;
      transition: width .8s ease;
    }
    
    .sliding-u-l-r-l-inverse:hover:after {
      width: 0%;
      background: transparent;
      transition: width 0s ease;
    }
    <div class="sliding-u-l-r-l-inverse">
      I want it to slide on the other direction.
    </div>

    【讨论】:

      【解决方案2】:

      改变左右的值声明。

      .sliding-u-l-r-l-inverse:beforeleft:0 组成,将其更改为 right:0 并在其他 pseudo selector :after right:0left:0 中相同。这会改变方向并使线从left to right 开始。

      .sliding-u-l-r-l-inverse {
        display: inline-block;
        position: relative;
        padding-bottom: 3px;
      }
      
      .sliding-u-l-r-l-inverse:before {
        content: '';
        display: block;
        position: absolute;
        right: 0;
        bottom: 0;
        height: 3px;
        width: 100%;
        transition: width 0s ease;
      }
      
      .sliding-u-l-r-l-inverse:after {
        content: '';
        display: block;
        position: absolute;
        left: 0;
        bottom: 0;
        height: 3px;
        width: 100%;
        background: blue;
        transition: width .8s ease;
      }
      
      .sliding-u-l-r-l-inverse:hover:before {
        width: 0%;
        background: blue;
        transition: width .8s ease;
      }
      
      .sliding-u-l-r-l-inverse:hover:after {
        width: 0%;
        background: transparent;
        transition: width 0s ease;
      }
      <div class="sliding-u-l-r-l-inverse">
        I want it to slide on the other direction.
      </div>

      【讨论】:

      • @Leshautsdurant 正如您所补充的那样,您找到了为下划线设置动画的代码,所以我建议您将那里的背景更改为不同的颜色,以了解它是如何工作的。
      • 欢迎@Leshautsdurant :-)
      猜你喜欢
      • 2015-12-25
      • 1970-01-01
      • 1970-01-01
      • 2017-10-06
      • 2015-12-12
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      • 2016-01-08
      相关资源
      最近更新 更多