网站或应用中,鼠标悬停效果能提升用户体验。然而,有时悬停时背景图标会被新的背景颜色遮盖。本文通过案例分析,讲解如何解决此问题。
一个搜索框,右侧图标在鼠标悬停时背景颜色改变,但图标却被新背景色遮挡:
相关CSS代码:
.tx_mmenu_together .donate-btn-header .lytop_search {
height: 40px;
margin: 0;
padding: 0;
float: left;
position: relative;
z-index: 1;
}
.tx_mmenu_together .donate-btn-header .lytop_search form {
width: 60px;
height: 40px;
margin: 0;
padding: 0;
position: relative;
}
.tx_mmenu_together .donate-btn-header .lytop_search form .sc_ipt {
width: 0;
height: 40px;
overflow: hidden;
margin: 0;
padding: 0;
position: absolute;
left: 0;
top: 0;
transition: all 0.5s;
}
.tx_mmenu_together .donate-btn-header .lytop_search form .sc_ipt input {
display: block;
width: 100%;
height: 40px;
overflow: hidden;
line-height: 40px;
color: #999999;
font-size: 14px;
margin: 0;
padding: 0 14px;
background-color: #fff;
border-radius: 20px 0 0 20px;
border: 1px solid #dfdfdf;
border-right: 0;
outline: none;
box-sizing: border-box;
}
.tx_mmenu_together .donate-btn-header .lytop_search form .sc_btn {
width: 60px;
height: 40px;
overflow: hidden;
margin: 0;
padding: 0;
border-radius: 0 20px 20px 0;
float: right;
}
.tx_mmenu_together .donate-btn-header .lytop_search form .sc_btn input {
display: block;
width: 60px;
height: 40px;
overflow: hidden;
margin: 0;
padding: 0;
background: #fff url('../img/home/search.png') center center no-repeat;
background-size: 40px 40px;
border: 0;
outline: none;
cursor: pointer;
}
.tx_mmenu_together .donate-btn-header .lytop_search:hover form .sc_ipt {
width: 260px;
left: -260px;
}
.tx_mmenu_together .donate-btn-header .lytop_search:hover form .sc_btn input {
background: #1a75bc url('../img/home/search-.png') center center no-repeat;
}悬停时,图标背景色从#fff变为#1a75bc,图片也从search.png变为search-.png。问题在于search-.png颜色设置可能与#1a75bc不匹配,导致图标不可见。
只需确保悬停时背景图颜色与悬停背景色一致即可。修改后的CSS代码:
.tx_mmenu_together .donate-btn-header .lytop_search form .sc_btn input {
background: #fff url('../img/home/search.png') center center no-repeat;
background-size: 40px 40px; /* 添加背景大小设置 */
}
.tx_mmenu_together .donate-btn-header .lytop_search:hover form .sc_btn input {
background: #1a75bc url('../img/home/search-.png') center center no-repeat;
background-size: 40px 40px; /* 添加背景大小设置 */
}通过确保search-.png颜色与#1a75bc匹配,悬停时图标清晰可见。 此处也补充了background-size属性,确保图片大小合适。
通过简单调整,即可解决图标被遮挡的问题,希望对您有所帮助。
以上就是如何解决鼠标悬浮时背景图标被背景颜色遮挡的问题?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号