2014-11-06 41 views
0

我有这两个按钮:CSS - 如何添加第二个渐变使该按钮变成透明的?

button

,我想实现这一目标的效果:

buttons

或者只是让 “按钮2” 半透明(淡出效果)上左边。
我认为这可以使用透明的第二个渐变实现。

编辑:“按钮1”和“按钮2”是表格的一部分。

这里是我的CSS:

.myButton { 

border: none; 
margin-right:0; 
padding-right:0; 
-moz-box-shadow: 0px 10px 14px -7px #273b73; 
-webkit-box-shadow: 0px 10px 14px -7px #273b73; 
box-shadow: 0px 10px 14px -7px #273b73; 
background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #595cb3), color-stop(1, #494099)); 
background:-moz-linear-gradient(top, #595cb3 5%, #494099 100%); 
background:-webkit-linear-gradient(top, #595cb3 5%, #494099 100%); 
background:-o-linear-gradient(top, #595cb3 5%, #494099 100%); 
background:-ms-linear-gradient(top, #595cb3 5%, #494099 100%); 
background: linear-gradient(to bottom, #595cb3 5%, #494099 100%); 
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#595cb3', endColorstr='#494099',GradientType=0); 
background-color:#595cb3; 
-moz-border-bottom-left-radius:8px; 
-webkit-border-bottom-left-radius:8px; 
border-bottom-left-radius:8px; -moz-border-top-left-radius:8px; 
-webkit-border-top-left-radius:8px; 
border-top-left-radius:8px; 
display:inline-block; 
cursor:pointer; 
color:#ffffff; 
font-family:arial; 
font-size:12px; 
font-weight:bold; 
padding:15px 60px; 
text-decoration:none; 
text-shadow:0px 1px 0px #3e5b8a; 
} 
.myButton:hover { 
background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #494099), color-stop(1, #595cb3)); 
background:-moz-linear-gradient(top, #494099 5%, #595cb3 100%); 
background:-webkit-linear-gradient(top, #494099 5%, #595cb3 100%); 
background:-o-linear-gradient(top, #494099 5%, #595cb3 100%); 
background:-ms-linear-gradient(top, #494099 5%, #595cb3 100%); 
background:linear-gradient(to bottom, #494099 5%, #595cb3 100%); 
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#494099', endColorstr='#595cb3',GradientType=0); 
background-color:#494099; 
} 



.myButton2 { 
border: none; 
margin-left:-20px; padding-left:0; -moz-box-shadow: 0px 10px 14px -7px #273b73; 
-webkit-box-shadow: 0px 10px 14px -7px #273b73; 
box-shadow: 0px 10px 14px -7px #273b73; 
background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #5986b3), color-stop(1, #406799)); 
background:-moz-linear-gradient(top, #5986b3 5%, #406799 100%); 
background:-webkit-linear-gradient(top, #5986b3 5%, #406799 100%); 
background:-o-linear-gradient(top, #5986b3 5%, #406799 100%); 
background:-ms-linear-gradient(top, #5986b3 5%, #406799 100%); 
background:linear-gradient(to bottom, #5986b3 5%, #406799 100%); 
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#5986b3', endColorstr='#406799',GradientType=0); 
background-color:#5986b3; 
-moz-border-bottom-right-radius:8px; 
-webkit-border-bottom-right-radius:8px; 
border-bottom-right-radius:8px; -moz-border-top-right-radius:8px; 
-webkit-border-top-right-radius:8px; 
border-top-right-radius:8px; 
display:inline-block; 
cursor:pointer; 
color:#ffffff; 
font-family:arial; 
font-size:12px; 
font-weight:bold; 
padding:15px 20px; 
text-decoration:none; 
text-shadow:0px 1px 0px #3e5b8a; 
} 
.myButton2:hover { 
background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #406799), color-stop(1, #5986b3)); 
background:-moz-linear-gradient(top, #406799 5%, #5986b3 100%); 
background:-webkit-linear-gradient(top, #406799 5%, #5986b3 100%); 
background:-o-linear-gradient(top, #406799 5%, #5986b3 100%); 
background:-ms-linear-gradient(top, #406799 5%, #5986b3 100%); 
background:linear-gradient(to bottom, #406799 5%, #5986b3 100%); 
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#406799', endColorstr='#5986b3',GradientType=0); 
background-color:#406799; 
} 

回答

1

如果你想使用CSS渐变您可以通过使用这样的事情做到这一点:

button { 
    height: 50px; 
    width: 105px; 
    display: block; 
    color: #fff; 
    float: left; 
    border: none; 
} 
.one{ 
     background-color: #4E4EA8; 
} 
.two{ 
    background: #2f36ef; /* Old browsers */ 
    background: -moz-linear-gradient(left, #2f36ef 0%, #2f36ef 0%, #4e4ea8 0%, #4e4ea8 5%, #557cb7 9%, #557cb7 100%); /* FF3.6+ */ 
    background: -webkit-gradient(linear, left top, right top, color-stop(0%,#2f36ef), color-stop(0%,#2f36ef), color-stop(0%,#4e4ea8), color-stop(5%,#4e4ea8), color-stop(9%,#557cb7), color-stop(100%,#557cb7)); /* Chrome,Safari4+ */ 
    background: -webkit-linear-gradient(left, #2f36ef 0%,#2f36ef 0%,#4e4ea8 0%,#4e4ea8 5%,#557cb7 9%,#557cb7 100%); /* Chrome10+,Safari5.1+ */ 
    background: -o-linear-gradient(left, #2f36ef 0%,#2f36ef 0%,#4e4ea8 0%,#4e4ea8 5%,#557cb7 9%,#557cb7 100%); /* Opera 11.10+ */ 
    background: -ms-linear-gradient(left, #2f36ef 0%,#2f36ef 0%,#4e4ea8 0%,#4e4ea8 5%,#557cb7 9%,#557cb7 100%); /* IE10+ */ 
    background: linear-gradient(to right, #2f36ef 0%,#2f36ef 0%,#4e4ea8 0%,#4e4ea8 5%,#557cb7 9%,#557cb7 100%); /* W3C */ 
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#2f36ef', endColorstr='#557cb7',GradientType=1); /* IE6-9 */ 


} 

这是我刚刚创建的例子:

http://jsfiddle.net/ncrd9y66/1/

我只是用http://www.colorzilla.com/gradient-editor/去pi从您的示例图像中提取颜色以在生成器中使用并将其复制到示例中。为了获得理想的效果,请自己玩一玩。这里是参考雷:http://www.colorzilla.com/gradient-editor/#2f36ef+0,2f36ef+0,4e4ea8+0,4e4ea8+5,557cb7+9,557cb7+100;Custom

(注:这是不是正是你可能会使用我挑出来迅速利用PS作为你如何能达到这种效果的例子相同的颜色。)

+0

嗯,它很好地完成,谢谢你:)但我仍然有一些问题,因为你可以看到我的CSS我使用悬停选择器,所以当我悬停时,它只突出显示按钮的一部分,这使得它很丑陋。 – 2014-11-06 17:14:54

+0

啊,好的。你想要的悬停效果是什么? – 2014-11-06 17:27:03

+0

要正确突出显示按钮(按钮1的所有紫色部分)(按钮2的所有蓝色部分) – 2014-11-06 17:31:55

0

您可以使用过滤器模糊..尝试,并把像素大小适合您的按钮。

例子:

.myButton2 { 
-webkit-filter: blur(5px); 
    -moz-filter: blur(5px); 
    -ms-filter: blur(5px); 
    -o-filter: blur(5px); 
filter: blur(5px); 
} 
+0

你能不能也在jsfiddle上做一个演示? – 2014-11-06 17:10:58

+0

好的,我会找你的。 1分钟! – vcrzy 2014-11-06 17:13:17

+0

看http://jsfiddle.net/3asZC/4/ – vcrzy 2014-11-06 17:15:33