在图像后创建 CSS 渐变
我正在构建一个颜色选择器,它在图像上使用 CSS 渐变。我有一个适用于 HSB 颜色选择的 CSS 渐变,但我无法为 HSB 颜色选择创建 CSS 渐变。您可以在以下位置查看原始渐变: http://jsfiddle.net/qVsFN/
渐变 1 应该看起来像渐变 2。是否可以这样做只用CSS?我尝试了几种方法,包括径向渐变,但没有成功。
这是我正在使用的 CSS 和标记:
#red_grad {
background: -moz-linear-gradient(0deg, rgba(255, 255, 255, 1), rgba(255, 0, 0, 1)) repeat scroll 0 0 transparent;
background: -webkit-gradient(linear, left center, right center, from(rgba(255, 255, 255, 1)), to(rgba(255, 0, 0, 1)));
height: 262px;
width: 262px;
}
#black_grad {
background: -moz-linear-gradient(90deg, rgba(0, 0, 0, 1), transparent) repeat scroll 0 0 transparent;
background: -webkit-gradient(linear, center bottom, center top, from(rgba(0, 0, 0, 1)), to(transparent)) repeat scroll 0 0 transparent;
height: 262px;
width: 262px;
}
<div id="red_grad">
<div id="black_grad">
</div>
</div>
I am building a color picker that uses CSS gradients instead on images. I have a CSS gradient that works for HSB color selection but I am unable to create a CSS gradient for HSB color selection. You can see the original gradient at:
http://jsfiddle.net/qVsFN/
Gradient 1 should look like gradient 2. Is it possible to do this with only css? I tryed several things including radial gradients with no luck.
Here is the css and markup I am using:
#red_grad {
background: -moz-linear-gradient(0deg, rgba(255, 255, 255, 1), rgba(255, 0, 0, 1)) repeat scroll 0 0 transparent;
background: -webkit-gradient(linear, left center, right center, from(rgba(255, 255, 255, 1)), to(rgba(255, 0, 0, 1)));
height: 262px;
width: 262px;
}
#black_grad {
background: -moz-linear-gradient(90deg, rgba(0, 0, 0, 1), transparent) repeat scroll 0 0 transparent;
background: -webkit-gradient(linear, center bottom, center top, from(rgba(0, 0, 0, 1)), to(transparent)) repeat scroll 0 0 transparent;
height: 262px;
width: 262px;
}
<div id="red_grad">
<div id="black_grad">
</div>
</div>
You can see it live at http://jsfiddle.net/qVsFN/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
HSL 饱和度-亮度平面可以用 2 个线性渐变来制作:
这是一个摆弄它: http://jsfiddle.net/leaverou/qVsFN/3/
注意:
改变色调怎么样?只需用
红色
替换新颜色的完全饱和版本(色调=任意,饱和度= 100,亮度= 50)——这就是您的颜色选择器!The HSL Saturation-Lightness plane can be made with 2 linear gradients:
Here's a fiddle with it: http://jsfiddle.net/leaverou/qVsFN/3/
Notes:
And what about changing the hue? Just substitute
red
for the fully saturated version of the new color (Hue = whatever, sat = 100, lightness = 50) -- and there's your color picker!