html - 在悬停动画 : Icon must get closer to the text, 现在它以相反的方式工作

标签 html css hover css-transitions css-animations

我想要的: 悬停时,如果“>”移近文本,我希望链接播放一个动画。

我有什么: 动画有效,但文本是靠近“>”的那个。我知道为什么会这样,但我不知道如何解决。如果图标在右侧,这应该很容易。

HTML:

<a href="#">Lees Meer</a>

CSS:

a {
  color: #0079D3;
  font-weight: 700;
  text-decoration: none;
}

a::before {
  content: '\f054';
  display: inline-block;
  font-family: 'FontAwesome';
  font-size: 0.65rem;
  margin-right: 1rem;
}

a:hover {
  color: #003082;
}

a:hover::before {
  margin-right: 0.5rem;
}

最佳答案

最简单的方法是将图标设置为绝对定位,在链接上为图标添加间距,然后使用left属性移动图标。

a {
    color: #0079D3;
    font-weight: 700;
    text-decoration: none;
    position: relative;
    padding: .5rem 1.5rem;
}

a::before {
  content: '\f054';
  display: inline-block;
  font-family: 'FontAwesome';
  font-size: 0.65rem;
  margin-right: 1rem;
  position: absolute;
  left: 0;
}

a:hover {
  color: #003082;
}

a:hover::before {
  left: 0.5rem;
}
<a href="#">Lees Meer</a>

关于html - 在悬停动画 : Icon must get closer to the text, 现在它以相反的方式工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39538026/

相关文章:

css - 将框架从 pure.css 更改为 bootstrap,而不更改标记

javascript - 令人困惑的悬停效果

javascript - 如何调用两个不同的 JavaScript Hover?

javascript - 如何在更改时附加 url

javascript - 使用 jQuery 在现有功能的基础上进行编码以检查输入框是否有值

html - 动态设置ionic2组件的Style属性

javascript - 如何更改事件菜单和子菜单项的样式

javascript - 检测客户端设备是否支持 :hover and :focus states

html - 当屏幕尺寸减小时,按钮格式变得杂乱无章

javascript - 为表格单元格添加悬停显示