我想要的: 悬停时,如果“>”移近文本,我希望链接播放一个动画。
我有什么: 动画有效,但文本是靠近“>”的那个。我知道为什么会这样,但我不知道如何解决。如果图标在右侧,这应该很容易。
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/