Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to do a curved line with css gradient?

Tags:

html

css

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.

enter image description here

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>
like image 845
DimSum Avatar asked Aug 03 '17 20:08

DimSum


3 Answers

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>
like image 71
Blazemonger Avatar answered Oct 20 '22 14:10

Blazemonger


You can use a pseudo element to draw the curve using a circle, then just use whatever gradient you want as the background(s)

a {
    background-color: lightblue;
    color: #fff;
    width: 200px;
    height: 40px;
    border-radius: 10px;
    margin-top: 50px;
    display: block;
    text-align: center;
    line-height: 40px;
    position: relative;
    z-index: 1;
    overflow: hidden;
}
a:after {
    content: '';
    position: absolute;
    background-color: blue;
    width: 600px;
    height: 200px;
    border-radius: 50%;
    top: 0;
    left: 0;
    transform: translate(-49%,0);
    z-index: -1;
}
<a>
  Some button
</a>
like image 3
Michael Coker Avatar answered Oct 20 '22 13:10

Michael Coker


I just modified a bit @Blazemonger's post. I fixed the position of the curved line.

a {
  background-image: radial-gradient(ellipse farthest-corner at -10% 250%, #3c84cc 0%, #315dc2 80%, #4e95d3 80%);
  color: white;
  width: 200px;
  height: 50px;
  border-radius: 10px;
  margin-top: 50px;
  display: block;
  text-align: center;
  line-height: 50px;
} 
<a>Some button</a>
like image 3
theAlexandrian Avatar answered Oct 20 '22 14:10

theAlexandrian