【问题标题】:On mouse hover the <a> tag underline transition from left to right and on mouse out the underline transition is back right to left鼠标悬停时 <a> 标签下划线从左到右过渡,鼠标移出时下划线过渡从右到左
【发布时间】:2026-02-14 01:00:01
【问题描述】:

现在,每当您悬停其中一个 &lt;a&gt; 元素时,一个 div 就会在悬停的元素下方从左向右过渡,但是,当我停止悬停时,它会立即消失而不是悬停回来。我怎样才能让它回到原来的位置?

到目前为止,我所拥有的是:

*, *:after, *:before {
    margin: 0;
    padding: 0;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    text-decoration: none;
    list-style-type: none;
    color: rgba(0, 0, 0, 0.8);
}
.links {
    display: flex;
    font-size: 1.1em;
    font-weight: 500;
    text-align: center;
}
.links a {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0px 30px;
    padding: 10px 0 10px 0;
    position: relative;
}
.links a:after{
    content: '';
    position: absolute;
    width: 0;
    height: 4px;
    display: block;
    margin-top: 25px;
    right: 0;
    background: #fff;
    transition: width .2s ease;
    -webkit-transition: width .3s ease;
}
.links a:hover:after{
    width: 100%;
    left: 0;
    background: rgba(0, 0, 0, 0.8);
}
        <div class='links'>
            <a href=''>
                <p>AAAAAAAAAAAAAAAA</p>
            </a>
            <a href=''>
                <p>AAAAAAAAAAAAAAAA</p>
            </a>
            <a href="">
                <p>AAAAAAAAAAAAAAAA</p>
            </a>
        </div>

【问题讨论】:

  • 在非悬停状态下移除 right:0 并只保留 left:0
  • 所以删除 right: 0 并将 left: 0 添加到 .links a:after ?不确定这是否是我的本意,但这并没有改变任何事情。
  • 从悬停中删除 left:0 并仅保留 right:0 所在的位置 .. 然后如果您想更改只需从右向左更改,则不应将它们悬停跨度>
  • 不要忘记您正在将背景从白色更改为另一种颜色
  • 但是现在它在悬停时从右到左出现,这不是我想要实现的。我希望它像现在一样在悬停时从左到右移动,然后在我停止悬停时从右到左返回。

标签: html css


【解决方案1】:

这是一个解决方案,试试这个。

.footer_menu {
  padding: 30px 0 0;
}
.footer_menu ul {
  padding: 0;
  text-align: left;
  margin-bottom: 0;
  list-style: none;
}
.footer_menu ul.bottom-menu {
  margin-bottom: 20px;
}
.footer_menu ul li {
  margin-bottom: 10px;
  list-style: none;
}
.footer_menu ul li a {
  text-decoration: none;
  color: #666666;
  padding-bottom: 3px;
  position: relative;
  -webkit-transition: all 0.5s ease;
  -o-transition: all 0.5s ease;
  transition: all 0.5s ease;
}
.footer_menu ul li a::before {
  content: '';
  position: absolute;
  bottom: -3px;
  left: 0;
  right: 100%;
  height: 2px;
  background: #e5e5e5;
  -webkit-transition: all 0.5s ease;
  -o-transition: all 0.5s ease;
  transition: all 0.5s ease;
  visibility: hidden;
}
.footer_menu ul li a:hover {
  color: #000000;
}
.footer_menu ul li a:hover::before {
  left: 0;
  right: 0;
  background: red;
  visibility: visible;
}
<div class="footer_menu">
<ul>
<li><a href="#">test test</a></li>
<li><a href="#">test test</a></li>
</ul>
<div>

【讨论】:

    【解决方案2】:

    您可以默认使用ease-in:hover ease-out

    【讨论】: