How to create a border lower color, such as a linear gradient on a div circle (see image file)

I want to create a circle div with a gradient effect on its borders, as shown below.

How can i achieve this?

enter image description here

This is where I get stuck:

.circle { background-color: #ffffff; text-align: ; width: 675px; height: 675px; border-radius: 50%; border-style: solid; border-width: 30px; border-left-color: #39c8e7; border-right-color: #39c8e7; border-bottom-color: // here I need linear gradient border-top-color: // this need to be transparent } 
+6
source share
3 answers

Using SVG:

For such figures, I would recommend SVG for two main reasons: (1) Arcs can be created very easily using SVG, and this means that the upper part will be transparent by default (2) the SVG stroke (border) can be set to a gradient . This means that we do not need to fill the arc / circle with a gradient, and then apply a white circle to it, and this, in turn, means that the central part can also be transparent.

The path elements that create two arcs use trigonometric equations to determine the endpoints of the arc. Thus, they can be easily modified if the arcs should be longer or shorter.

The gradients used are roughly equivalent to those that were called into question, but closer similarity can be achieved by further setting the color breakpoints.

Demo:

 div { position: relative; height: 250px; width: 250px; border-radius: 50%; } svg { position: absolute; height: 100%; width: 100%; top: 0px; left: 0px; } path { fill: transparent; stroke-width: 4; } #left-half { stroke: url(#left-border); } #right-half { stroke: url(#right-border); } /* just for demo */ body { background: radial-gradient(circle at center, aliceblue, steelblue); min-height: 100vh; } 
 <div> <svg viewBox='0 0 104 104'> <linearGradient id='left-border' gradientUnits='objectBoundingBox' gradientTransform='rotate(50,0.5,0.5)'> <stop offset="0%" stop-color="rgb(71, 207, 215)" /> <stop offset="100%" stop-color="rgb(113, 230, 178)" /> </linearGradient> <linearGradient id='right-border' gradientUnits='objectBoundingBox' gradientTransform='rotate(310,0.5,0.5)'> <stop offset="0%" stop-color="rgb(217, 63, 177)" /> <stop offset="100%" stop-color="rgb(217, 56, 111)" /> </linearGradient> <path d='M52,102 A50,50 0 0,1 19.86,13.69' id='left-half' /> <path d='M52,102 A50,50 0 0,0 84.14,13.69' id='right-half' /> </svg> </div> 

Output screenshot: (background added to show circle is transparent except for borders)

enter image description here


CSS usage:

Using CSS, you can use two separate linear-gradient background images (one for the left half of the border and the other for the right half) that have an angle and then overlay them with two white circles (created using radial-gradient ) to create one same effect as in the question. To make the top part transparent, you can put all the material in a pseudo-element, place it just above the parent element, and then pin the top part using overflow: hidden for the parent.

The disadvantage is that the central part of the circle should be a solid color (white or something else). It cannot be transparent. We can use mask images to create a transparent center, but browser support for it is very low. It is supported only by browsers working with WebKit.

Demo:

 div { position: relative; height: 250px; width: 250px; overflow: hidden; } div:after { position: absolute; content: ''; height: 100%; width: 100%; left: 0px; top: -20%; background: radial-gradient(circle at center, white 64%, transparent 65%), radial-gradient(circle at 50% -50%, white 50%, transparent 51%), linear-gradient(310deg, rgb(113, 230, 178), rgb(71, 207, 215)), linear-gradient(50deg, rgb(217, 63, 177), rgb(217, 56, 111)); background-size: 100% 100%, 100% 100%, 50% 100%, 50% 100%; background-position: left top, left top, left top, right top; background-repeat: no-repeat; border-radius: 50%; } 
 <div></div> 

Note. . One of the radial gradients could be avoided using the same method that the shaft used in its answer, but the other (located above the element) cannot be avoided, since this approach does not use a constant color for the left and right borders. He is trying to imitate the image in question, which also does not have a constant color on the left and right. Achieving this effect using borders will be tough. (This does not mean that the other answers are bad / wrong, but only this answer is different).

+6
source

You can use 2 different backgrounds, one in the base to get the gradient, and the other on top to cover it on white.

By changing the clip and the origin of both, you can make a basic show only in the border zone

 .test { width: 150px; height: 150px; border-radius: 50%; border: solid 10px transparent; border-left-color: cyan; border-right-color: red; background-image: linear-gradient(white, white), linear-gradient(90deg, cyan 20%, blue 50% , magenta 50%, red 100%); background-clip: padding-box, border-box; background-origin: padding-box, border-box; background-size: 100% 100%, 100% 50%; background-position: center center, center bottom; background-repeat: no-repeat; } body { background-color: yellow; } 
 <div class="test"></div> 

Another option is to make the background transparent.

I use 2 pseudo-elements, trimmed so that they use only one half (right or left) and with variable shadows to get the effect.

 .test { width: 430px; height: 430px; border-radius: 50%; position: relative; overflow: hidden; } .test:before, .test:after { content: ""; position: absolute; width: 400px; height: 400px; border-radius: 50%; left: 15px; top: 15px; } .test:before { box-shadow: -31px 232px 107px -142px rgb(110, 228, 180), -228px -71px 0px -92px #47CFDA, -213px 71px 0px -77px rgba(66, 205, 221, 0.948), -31px 232px 0px -77px rgb(66, 205, 221); clip: rect(0px, 200px, 1000px, -15px); } .test:after { box-shadow: 42px 256px 107px 108px #D93EB2, 384px 60px 0px 132px #D9386F; clip: rect(0px, 450px, 1000px, 200px); } body { background: radial-gradient(circle at center, aliceblue, steelblue); min-height: 100vh; } 
 <div class="test"></div> 

body background copied from Harry's answer

+5
source

You should use SVG for these typical things, otherwise you can play with the gradient and shadow for the shadow (or pseudo-elements) to hide parts of the gradient:

here is an example to give an idea (medium and hard to maintain ...)

 .circle { background-color: #ffffff; text-align: ; width: 75px;/* update this */ height: 75px;/* update this */ border-radius: 50%; text-align: center; line-height: 75px; border-style: solid; border-width: 30px; border-left-color: #39c8e7; border-right-color: #39c8e7; border-bottom-color: transparent; border-top-color: transparent; background: linear-gradient(115deg, #39cbe7 40%, black 80%) -10px 60px no-repeat, linear-gradient(-115deg, #39cbe7 40%, black 80%) 40px 60px no-repeat;/* update background-position and whatever else you need */ background-size: 67%;/* update this */ box-shadow: inset 0 0 0 200px white;/* update this */ } 
 <div class="circle"> test</div> 
+4
source

All Articles