Create multi coloured border box using conic gradient
Hello, Folks 👋🏻
Problem: I'm struggling to add a multicolored border box around a black box content using a conic gradient.
Context: I have a paragraph tag that contains content, and I’ve styled it to transform the paragraph content into a black box. Then, I added an imaginary box behind this content box using the
::after
pseudo-class to create a multicolored border around it with a conic-gradient.
I know I can adjust the top, left, width, and height properties to position the pseudo-element behind the content box, but I don't want to control the border that way. Instead, I want to control it by padding or another method, so that whenever I increase the padding, the border width also increases.
Codepen: https://codepen.io/HritikDj/pen/XWLNjPB ( I want to create a similar effect which is there in the screenshot below)3 Replies
here a simple example (you'll have to play with the gradient yourself)
the linear-black gradient is clipped to the padding-box (so won't touch the border region)
the conic-gradient is clipped to the border-box
order of the bg's is important ( first line is the top layer )
because the border is transparent, you'll see the gradient there. With border-size you can control the thickness
Thanks, @Mannix @MarkBoots that was quite helpful 🫡