Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Gradient around a point

Tags:

css

canvas

I'm wondering if anybody knows, wether its possible to create a gradient like this using CSS only? I know it can be done using canvas but is it possible without?

enter image description here

like image 551
Liam Avatar asked Apr 04 '14 09:04

Liam


People also ask

How do you add a gradient to a circle in CSS?

radial-gradient() The radial-gradient() CSS function creates an image consisting of a progressive transition between two or more colors that radiate from an origin. Its shape may be a circle or an ellipse. The function's result is an object of the <gradient> data type, which is a special kind of <image> .

Can I use CSS conic gradient?

While it is possible to create pie charts, checkerboards, and other effects with conic gradients, CSS images provide no native way to assign alternative text, and therefore the image represented by the conic gradient will not be accessible to screen reader users.

What is the difference between linear and radial gradient?

CSS defines three types of gradients: Linear Gradients (goes down/up/left/right/diagonally) Radial Gradients (defined by their center) Conic Gradients (rotated around a center point)


1 Answers

This is about as close as I could get without staying up all night fiddling with it, but YES, it is possible! [Only with trickery, though, sorry; I don't know of any way to create a legitimate CSS3 gradient ring like that, but the at the least, this is pure HTML/CSS!]

JSFIDDLE

CSS3 Gradient Ring

CSS

[I apologize for it being messy]

.tophalf {
position:absolute;
width: 250px; height:125px;
-webkit-border-top-left-radius: 193px;
-webkit-border-top-right-radius: 193px;
-moz-border-radius-topleft: 193px;
-moz-border-radius-topright: 193px;
border-top-left-radius: 193px;
border-top-right-radius: 193px;

background: -moz-linear-gradient(left, #db9771 1%, #cc5f7f 51%, #c30380 100%);
background: -webkit-gradient(linear, left top, right top, color-stop(1%,#db9771), color-stop(51%,#cc5f7f), color-stop(100%,#c30380));
background: -webkit-linear-gradient(left, #db9771 1%,#cc5f7f 51%,#c30380 100%);
background: -o-linear-gradient(left, #db9771 1%,#cc5f7f 51%,#c30380 100%);
background: -ms-linear-gradient(left, #db9771 1%,#cc5f7f 51%,#c30380 100%);
background: linear-gradient(to right, #db9771 1%,#cc5f7f 51%,#c30380 100%);
}

.inner {
 position: relative; z-index: 1;
 top: 20px; left: 20px;
 width: 210px; height: 210px;
 background-color: white;
 border-radius: 100%;
}

.bottomhalf {
position:absolute;
top:133px;
width: 250px; height:125px;
-webkit-border-bottom-right-radius: 193px;
-webkit-border-bottom-left-radius: 193px;
-moz-border-radius-bottomright: 193px;
-moz-border-radius-bottomleft: 193px;
border-bottom-right-radius: 193px;
border-bottom-left-radius: 193px;

background: -moz-linear-gradient(left, #db9771 1%, #edc552 51%, #ffec00 100%);
background: -webkit-gradient(linear, left top, right top, color-stop(1%,#db9771), color-stop(51%,#edc552), color-stop(100%,#ffec00));
background: -webkit-linear-gradient(left, #db9771 1%,#edc552 51%,#ffec00 100%);
background: -o-linear-gradient(left, #db9771 1%,#edc552 51%,#ffec00 100%);
background: -ms-linear-gradient(left, #db9771 1%,#edc552 51%,#ffec00 100%);
background: linear-gradient(to right, #db9771 1%,#edc552 51%,#ffec00 100%);
}

HTML

<div class='container'>
   <div class='tophalf'></div>
   <div class='inner'></div>
   <div class='bottomhalf'></div>
</div>

How'd I do it?

To be short and simple, I put two half-circles together, giving each half a different gradient, but keeping the starting color on the left side identical for both, ensuring that the 'seam' would only be on one side.

Then, I put a white full circle right in the center of the two half-circles, hiding everything in the middle and successfully creating a gradient ring.

sources?

Edit: Oops! I couldn't have done it without the Gradient Editor.

like image 176
Leaf Avatar answered Sep 20 '22 09:09

Leaf