css - 悬停的背景颜色变化打破了模拟+显示
问题描述
我有一个带有线性渐变和背景大小的 + 和 - 符号的按钮。如果我添加一个悬停状态,只是改变颜色,+ 和 - 效果不起作用。知道为什么会这样吗?
这是笔:https ://codepen.io/miguelrivero/pen/gOraZaM
.AddToBagButton__decrease,
.AddToBagButton__increase {
background: linear-gradient(#2e8561, #2e8561) top left,
linear-gradient(#2e8561, #2e8561) top right,
linear-gradient(#2e8561, #2e8561) bottom left,
linear-gradient(#2e8561, #2e8561) bottom right;
background-repeat: no-repeat;
border: 13px solid #2e8561;
box-sizing: border-box;
border-radius: 50%;
&:hover {
background: linear-gradient(#215e45, #215e45) top left,
linear-gradient(#215e45, #215e45) top right,
linear-gradient(#215e45, #215e45) bottom left,
linear-gradient(#215e45, #215e45) bottom right;
border: 13px solid #215e45;
}
}
.AddToBagButton__decrease {
background-size: 100% calc(50% - .5px);
left: 0;
}
.AddToBagButton__increase {
background-size: calc(50% - 1px) calc(50% - .5px);
right: 0;
}
解决方案
知道为什么会这样吗?
因为您正在覆盖background-size
您为按钮指定的内容,所以通过background
速记属性应用更改后的渐变,这会将您未指定的所有单个背景属性重置为默认值。(.AddToBagButton__decrease:hover
比 具有更高的特异性.AddToBagButton__decrease
。)
做那个
&:hover {
background-image: …
反而。(渐变在 CSS中被视为图像。)
推荐阅读
- c - 为什么不能使用 malloc 调整 C 中的数组大小?
- c# - signin-oidc 重定向不起作用 OpenId Connect
- c# - 使用 ListView 时,如何在 Xamarin Forms 中设置自定义控件绑定到父视图模型属性?
- c++ - FREAK 不是 cv 的成员?
- angular - Angular 2+ HttpErrorResponse 超时未返回正确状态
- java - Spring-boot & Java FindById 返回 null 而不是数字
- html - CSS 特定问题
- java - MicroMeter:删除/禁用某个标签
- swift - iOS12:transitionController 已弃用
- c++ - 如何使用 Visual Studio 2015 正确调试 MFC 容器