I want to create a border animation for a button element. The design is that the ends of the slanted rectangle are open and then close on hover.
This is what we're trying to do (excuse my artistic "style"):
Here's some code and a codepen example:
a svg rect {
stroke: red;
stroke-width: 5;
transition: 1s;
stroke-dasharray: 100%;
stroke-dashoffset: 0;
}
a:hover svg rect {
stroke-dasharray: 0%;
stroke-dashoffset: 0;
}
I'm having trouble understanding the math behind stroke-dasharray, but it seems this should be possible without too much complex math.
The other issue is that it would need to be responsive. So the button can contain different amounts text.
Let me know if you need further clarification.