【发布时间】:2017-03-07 15:28:56
【问题描述】:
通过以下代码,我得到了从左到右的悬停下划线效果。
.underline {
display: inline;
position: relative;
overflow: hidden;
}
.underline:after {
content: "";
position: absolute;
z-index: -1;
left: 0;
right: 100%;
bottom: -5px;
background: #000;
height: 4px;
transition-property: left right;
transition-duration: 0.3s;
transition-timing-function: ease-out;
}
.underline:hover:after,
.underline:focus:after,
.underline:active:after {
right: 0;
}
<p>hello, link is <a href="#" class="underline">underline</a>
</p>
当您不悬停时,:after 元素会返回到左侧,即初始状态。当您离开悬停时,:after 会向右而不是向左移动吗?
【问题讨论】:
-
您可以使用 jQuery hover 函数向您的锚标记添加一个类,并在您在 jQuery 脚本中定义的类中添加一些样式。
-
您是否正在寻找类似的东西 - stackoverflow.com/questions/28623446/…?
标签: css css-transitions transitions