html - 悬停时的相对背景颜色
问题描述
我有一个简单的 html 代码,如下所示:
button {
position: absolute;
font-size: x-large;
border-radius: 25px;
width: 140px;
height: 50px;
margin: 5px;
color: white;
border: none;
cursor: pointer;
}
#home-btn {
background: orange;
}
#panel-btn {
background: yellowgreen;
right: 0;
}
<button title="home" id="home-btn" class="fa fa-home"></button>
<button title="panel" id="panel-btn" class="fa fa-key"></button>
如何将背景颜色设置为比默认背景颜色深的颜色?
这是一个来自我想要的页面的 gif:
抱歉英语不好。
解决方案
您可以使用CSS 过滤器:
button {
position: absolute;
font-size: x-large;
border-radius: 25px;
width: 140px;
height: 50px;
margin: 5px;
color: white;
border: none;
cursor: pointer;
transition: filter .2s;
}
button:hover {
filter: brightness(0.9);
}
#home-btn {
background: orange;
}
#panel-btn {
background: yellowgreen;
right: 0;
}
<button title="home" id="home-btn" class="fa fa-home"></button>
<button title="panel" id="panel-btn" class="fa fa-key"></button>
从我在该 GIF 中看到的内容来看,您想要的可能是增加饱和度:
button {
position: absolute;
font-size: x-large;
border-radius: 25px;
width: 140px;
height: 50px;
margin: 5px;
color: white;
border: none;
cursor: pointer;
transition: filter .2s;
}
button:hover {
filter: saturate(400%);
}
#home-btn {
background: orange;
}
#panel-btn {
background: yellowgreen;
right: 0;
}
<button title="home" id="home-btn" class="fa fa-home"></button>
<button title="panel" id="panel-btn" class="fa fa-key"></button>
推荐阅读
- javascript - 如何使用 javascript 将图像附加到特定的网格项
- r - 多目标优化约束问题:R
- permissions - 创建具有权限的静态角色的最佳实践
- sql - 基于第三个表连接两个表(SQLite)
- php - 我可以同时将数据从 php 保存到 json 和 MySQL 数据库吗?
- reactjs - React Context API 没有更新我的状态:做错了吗?(减速机部分)
- python - mplot3d 的 scatter 的“颜色”参数的全部容量是多少?
- javascript - 新手:不可能通过谷歌脚本和表单在邮件中获取我附加的 pdf
- javascript - JavaScript 表单输入
- java - 如何更改二维数组的大小?