My goal is to create a resizable SVG with a fixed aspect ratio by placing it inside a <div>
that adjusts to the size of the SVG. I'm using the Rust Seed library, so although my code isn't in JavaScript, you should still be able to understand the concept:
div![ // wrapping div
style!{
St::MaxWidth => "100%";
St::MaxHeight => "100%";
St::Resize => "both";
St::Overflow => "auto";
},
svg![ // contained svg
style!{
St::BackgroundColor => "gray";
},
attrs!{
At::Width => "100%",
At::Height => "100%",
At::ViewBox => format!("0 0 {} {}", width, height),
At::PreserveAspectRatio => "xMinYMin meet",
},
text![ // svg text
"Example SVG"
],
]
]
I've been facing an issue where the wrapper does not dynamically match the size of the SVG. I've attempted using "min-content" and "max-content" on the MaxWidth
and MaxHeight
attributes, but it hasn't produced the desired result. How can I make this setup work as intended?
Here's the current behavior: https://i.sstatic.net/55EGh.gif