有没有办法用一种颜色填充一半的按钮背景?

时间:2013-04-12 13:20:25

标签: javascript css colors

有没有办法用一种颜色填充一半的按钮背景?

像:

|BLUEBLUEBLUE REDREDREDRED|

1 个答案:

答案 0 :(得分:4)

是的,您可以在具有渐变背景的CSS中执行此操作。

background-image: linear-gradient(left , rgb(255,0,0) 50%, rgb(0,0,255) 51%);
background-image: -o-linear-gradient(left , rgb(255,0,0) 50%, rgb(0,0,255) 51%);
background-image: -moz-linear-gradient(left , rgb(255,0,0) 50%, rgb(0,0,255) 51%);
background-image: -webkit-linear-gradient(left , rgb(255,0,0) 50%, rgb(0,0,255) 51%);
background-image: -ms-linear-gradient(left , rgb(255,0,0) 50%, rgb(0,0,255) 51%);

background-image: -webkit-gradient(
    linear,
    left bottom,
    right bottom,
    color-stop(0.5, rgb(255,0,0)),
    color-stop(0.51, rgb(0,0,255))
);

使用此网站根据您的需要对其进行自定义:http://gradients.glrzad.com/

这是一个小提琴:http://jsfiddle.net/GNCRL/