问题描述
我从一个客户那里得到了这个设计,按钮中有两层渐变.棘手的是,其中一层具有弯曲的边缘.我模拟了按钮,希望您能明白我在说什么.
I have this design from a client with two layers of gradients in a button. The tricky thing is, one of the layers has a curved edge. I've mocked up the button so you have a sense of what I'm saying, hopefully.
我设法做的是一条直边(见代码片段,色差不重要,只需要曲线).有没有人以前做过这个?还是必须是背景图片?谢谢!
What I managed to do is a straight edge (see code snippet, color difference is not important, just need the curve). Does anyone have done this before? Or does it have to be a background image? Thanks!
附言我也想过在伪元素上使用径向渐变并绝对定位它,但无法获得像线性渐变一样的精确直边.
P.S. I also thought about using radial gradient on a pseudo element and absolute position it, but couldn't get the exact straight edge look like the linear gradient.
a {
background-image: linear-gradient(-155deg,rgba(74,148,214,.4) 45%,rgba(255,255,255,.08) 15%),linear-gradient(258deg,rgba(87,238,255,.1),rgba(77,108,211,.2));
background-color: rgba(74,148,214,.9);
color: #fff;
width: 200px;
height: 40px;
border-radius: 10px;
margin-top: 50px;
display: block;
text-align: center;
line-height: 40px;
}
<a>
Some button
</a>
推荐答案
您可以使用 radial-gradient
而不是线性:
You can get pretty close by using a radial-gradient
instead of linear:
a {
background-image:
radial-gradient(ellipse farthest-corner at 0 140%, #3c84cc 0%, #316dc2 70%, #4e95d3 70%);
color: white;
width: 200px;
height: 50px;
border-radius: 10px;
margin-top: 50px;
display: block;
text-align: center;
line-height: 50px;
}
<a>
Some button
</a>
这篇关于是否可以用css渐变做一条曲线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!