That’s… a lot of SVG for drawing a circle.
Someone will do this better than me, but…
I’ma clean that up a bit. I’m also going to steal code shamelessly from elsewhere, because people with bigger brains than me have done this already.
First, we’re going to pull the SVG out of the file and slap it into the HTML. This is so that the CSS can fiddle with it (it can’t muck with the contents of a file).
I’m also going to make the following changes:
- Your SVG’s width and height are 144x137, for a circle you’re drawing in a 100x100 space. That seems arbitrary, and the numbers will make more sense if we just make it 100x100 to start with.
- Same goes for the viewBox.
<svg width="100" height="100" viewBox="0 0 100 100" fill="none" xmlns="http://www.w3.org/2000/svg" class="ellipse-image">
Now that the world is in a cohesive grid system that makes sense to my brain, let’s draw a circle using… a circle.
<circle class="fillme"></circle>
(No, I didnt set any of the values for it yet. You’ll see.)
Now we… close the SVG. Because we’re done with it.
</svg>
Now the messy part. The CSS to make it work. Here comes the part where i steal shamelessly a lot.
First, we’re going to use a bunch of variables to let the browser do math and make our numbers easier.
.ellipse-image {
position: absolute;
width: 100px;
height: 100px;
bottom: 0;
right: 0; /* All this was your code */
--size: 100px;
--half-size: calc(var(--size) / 2);
--stroke-width: 5px;
--radius: calc((var(--size) - var(--stroke-width)) / 2);
--circumference: calc(var(--radius) * pi * 2);
--dash: calc((var(--progress) * var(--circumference)) / 100);
--progress: 25; /* We start at a quarter-circle. */
}
Could we have done the math ourselves? Sure. Am i going to when the entire thing is based off of the size of the circle? Nope. Computers away!
We also need to tell our circle what its parameters are, because circles are picky like that and want to know things like… where they should be centered and how big they should be and whatnot. We’ve already got values kicking around in variables, we might as well use them here too.
.fillme {
cx: var(--half-size);
cy: var(--half-size);
r: var(--radius);
stroke-width: var(--stroke-width);
fill: none;
stroke-linecap: round;
stroke-dasharray: var(--dash) calc(var(--circumference) - var(--dash));
stroke: #AF2626;
transition: stroke-dasharray 0.3s linear 0s;
}
The transition will be necessary to ‘undo’ the animation when the hover ends. Note that the dasharray is based on --dash, which itself is based on --progress.
We then attach the change in progress value to a hover and let the transition kick in:
.ellipse-image:hover {
--progress: 100
}
and we get…
(Note that i’m missing some of your CSS, so the text doesnt look right, but you get the point.)
[EDIT: And eventually i’ll remember i gave my circle a class.