html - 将内容添加到带有过渡的悬停 anchor 链接

标签 html css css-transitions

我想知道如何存档将鼠标悬停在页面上的 anchor 链接时出现的图标。

我开始了一个小片段,我认为它可以实现我预期的行为,但它却留下了一个空白。当您将鼠标悬停在 anchor 上时,文本的大小应该会扩展(增长)。

如何存档?

a:after {
    content:" 🔗";
    position: relative;
    opacity: 0;
    left: -20px;
    -webkit-transition: all 250ms;
    transition: all 250ms;
}
a:hover:after {
    opacity: 1;
    left: 0px;
    -webkit-transition: all 250ms;
    transition: all 250ms;
}
<p>This is a <a href='http://stackoverflow.com'>Test</a>. And I would like to link you on <a href='http://stackoverflow.com'>Stackoverflow</a> if you have any questions.</p>

最佳答案

您可以使用负值 margin-left: -20px; 在没有悬停的情况下向后拉空隙。然后,当用户将鼠标悬停在文本上时,您可以制作 margin-left: 0; 以重新添加间隙以适合图标。

a:after {
    content:" 🔗";
    position: relative;
    opacity: 0;
    left: 0px;
    margin-left:-20px;
    -webkit-transition: all 250ms;
    transition: all 250ms;
}
a:hover:after {
    opacity: 1;
    left: 0;
    margin-left:0;
    -webkit-transition: all 250ms;
    transition: all 250ms;
}
<p>This is a <a href='http://stackoverflow.com'>Test</a>. And I would like to link you on <a href='http://stackoverflow.com'>Stackoverflow</a> if you have any questions.</p>

编辑: OP - 如果您使用 -26px,就会发生这种情况。句号/句点被插入字母 t。这是因为添加的间隙只有 20px 宽,因此,您只需减去 20pxenter image description here

关于html - 将内容添加到带有过渡的悬停 anchor 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46223274/

相关文章:

css - 我想要 wordpress 中菜单的颜色

php - 无法访问获取 dBase 数据。登录页面不断循环回到同一页面

javascript - 通过单击复选框将类添加到所有 <tr>

css - 如何根据屏幕尺寸/设备使用特定的 CSS 样式

css - Bootstrap 4 最大高度 div

jquery - 如何使用 Jquery 使下划线淡入? (背景图像?)

html - 悬停过渡时的颜色变化不起作用(CSS)

javascript - 如何从 JavaScript 设置和触发 css 转换

javascript - 使用canvas HTML5 进行图像幻灯片放映

php - 带有大写和小写符号的 .htaccess 和 href 链接