【发布时间】:2017-11-03 17:49:09
【问题描述】:
我有几个带有不同背景图像的按钮。 我想实现在默认情况下对它们进行灰度过滤,并在悬停时删除灰度过滤器。
我已经有了,但问题是按钮的文本也是灰色的,我想避免这种情况。 我不知道如何只在按钮背景上应用灰度滤镜,而不是在文本上。
现在我有一个用于按钮的主要 css 类
.box {
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
position:relative;
color: red;
cursor:pointer;
text-align: center;
width: 160px;
height: 160px;
}
.box:hover {
-webkit-filter: grayscale(0%);
filter: grayscale(0%);
color: blue;
}
我在 html 代码中为每个按钮应用背景
<button onclick="buttonFunction()" button class="button box" style="background: url(background1.jpg); background-size: 100%;" >Gray button text:( </button>
知道如何添加灰度过滤器按钮背景并使按钮文本保持彩色吗?
谢谢
【问题讨论】:
-
使用伪元素并仅对其应用过滤器。它不会影响文本。
标签: css button text background grayscale