html - 悬停时在按钮中显示图像
问题描述
这是来自 W3Schools 的代码。它是一个动画按钮,当您将鼠标悬停时,它会在文本旁边显示一个窄。您可以在.button span:after {content: '\00bb'...}
. 如何用我想要的任何图像替换窄 ('\00bb')?可能很容易,但我是新手,我无法弄清楚。谢谢你。
.button {
border-radius: 4px;
background-color: darkgreen;
border: none;
color: #FFFFFF;
text-align: center;
font-size: 28px;
padding: 20px;
width: 200px;
transition: all 0.5s;
cursor: pointer;
margin: 5px;
}
.button span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
}
**.button span:after {
content: '\00bb'**;
position: absolute;
opacity: 0;
top: 0;
right: -100px;
transition: 0.5s;
}
.button:hover span {
padding-right: 55px;
}
.button:hover span:after {
opacity: 1;
right: 0;
}
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<h2>Animated Button</h2>
<button class="button"><span>Hover </button>
解决方案
您的实际内容与某些角色有关。您可以在此处从字体加载不同的图标或上传图像。然后您必须将内容留空并将图像放在背景中。
content: "";
background: url('../images/your-image.png') no-repeat;
推荐阅读
- python - 以表格形式从文本文件中读取字典
- python - 在 Python 中将超过 65535 行写入 csv 文件?
- python - Python 连接到 ODBC 2.x 数据库
- ruby - Ruby 中相等运算符的顺序重要吗?
- jquery - 如何在我的ajax查询中传递多个数据并通过api保存数据
- python - 无法连接不同的主机来检索值
- javascript - 解构打字稿函数
- reactjs - 400 Bad Request 将纯 HTTP 请求发送到 HTTPS 端口,同时使用 Docker 将 Django 部署到 AWS 并让我们加密
- javascript - 如何通过nodejs向twimlResponse拨号添加参数
- javascript - 从特定消息中删除特定用户反应 - Discord.js