Convert SVG to CSS properties

Hey, I saw this video of Kevin https://www.youtube.com/watch?v=4ALLynsZ0u0 I was wondering if anyone knows some tool to import a svg file and have it be converted in this way with border-radius. Or is there another better way? I know you can import SVG via a link the the point of me wanting to do it this way is to improve speeds on my website.
Kevin Powell
YouTube
Create interesting blob shapes with CSS
We can do more with border-radius than you might have thought! πŸ”— Links βœ… The CodePen: https://codepen.io/kevinpowell/pen/PoQEPvG βœ… Fancy Border Radius Generator: https://9elements.github.io/fancy-border-radius/ ⌚ Timestamps 00:00 - Introduction 00:43 - Understand how it works 03:16 - The easy way 03:48 - Having fun with this #css #DubbedWithA...
8 Replies
b1mind
b1mindβ€’3mo ago
You wouldn't That tool he used is specific, and isn't correlated to SVG πŸ€” You can use SVG in a clip path though. Or do SVG masking in itself.
Jochem
Jochemβ€’3mo ago
what you ask is also pretty much impossible, because SVG offers an infinite number of shapes, where a border radius solution can only make amorphous blobs that look a lot like that one in the thumbnail you can only have four smooth curves using the border radius trick. Not three, not five, exactly four
Chooβ™šπ•‚π•šπ•Ÿπ•˜
SVG cannot be converted to border radius for the reasons stated in the prior comments, but many SVGs can be converted to clip paths. You can even use the path syntax for a clip path, which allows you to copy the actual path data directly from SVG code. This does have a limitation, because an SVG can have multiple paths. The clip path only takes one path. Also, an SVG can contain other parts that are not paths.
Rowe2ry
Rowe2ryβ€’3mo ago
The way I'd use SVGs without linking them is by using SVG in CSS so you're on the right track. What I do is open an svg file in a text editor and copy the raw code. I like to use this tool https://yoksel.github.io/url-encoder/ copy the output in this "Ready for CSS" block paste it into a root variable for your project (remove the beginning of the string that says "background-image")
--svg-rainbow-circle: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle r='50' cx='50' cy='50' fill='tomato'/%3E%3Ccircle r='41' cx='47' cy='50' fill='orange'/%3E%3Ccircle r='33' cx='48' cy='53' fill='gold'/%3E%3Ccircle r='25' cx='49' cy='51' fill='yellowgreen'/%3E%3Ccircle r='17' cx='52' cy='50' fill='lightseagreen'/%3E%3Ccircle r='9' cx='55' cy='48' fill='teal'/%3E%3C/svg%3E");
--svg-rainbow-circle: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle r='50' cx='50' cy='50' fill='tomato'/%3E%3Ccircle r='41' cx='47' cy='50' fill='orange'/%3E%3Ccircle r='33' cx='48' cy='53' fill='gold'/%3E%3Ccircle r='25' cx='49' cy='51' fill='yellowgreen'/%3E%3Ccircle r='17' cx='52' cy='50' fill='lightseagreen'/%3E%3Ccircle r='9' cx='55' cy='48' fill='teal'/%3E%3C/svg%3E");
Then you can use it for pseudo elements.
.numeric-spin-up::before {
content: var(--svg-rainbow-circle);
}
.numeric-spin-up::before {
content: var(--svg-rainbow-circle);
}
No description
Rowe2ry
Rowe2ryβ€’3mo ago
I mainly do this to override existing UI library pseudo element content but you can use it like this as well. Then it will ship the svg info with the stylesheet instead of a separate external linked file. You can also put raw SVG code right in your HTML markup I'm doing this here for the "-" & "+" buttons on this numeric input counter
Rowe2ry
Rowe2ryβ€’3mo ago
This is how I'm doing these "-" and "+" icons for this numeric input. Our UI/UX person gave me a Figma with SVGs I could export.
No description
EasyToKill_ (long break)
EasyToKill_ (long break)OPβ€’2mo ago
but the svg does it load from the url or from the css?
Rowe2ry
Rowe2ryβ€’2mo ago
From the css. The css says URL, but its the actual SVG file data its reading. The browser isn't making any network calls to load the svgs, it comes with the stylesheet
Want results from more Discord servers?
Add your server