I've been working on the Order Summary Component challenge from FrontEnd Mentor and am a little confused about dynamically resizing <svg/> elements. Just want to make sure I”m doing things correctly as I don’t know much about CSS.
My questions are as follows:
- I’m placing the background pattern as a sibling to the card
component, setting the container to
position: relativeand the.backgrounddiv toposition: absolute; inset: 0;. Is this the correct method to float a background image behind a card? Or should I be going about it differently? - I set the svg
viewboxto match the providedwidthandheightof the element and removed thewidthandheight(fromwidth="450" height="220"toviewbox="0 0 450 220). I then set the.backgrounddiv tooverflow: hidden;which clips the pattern as the viewport is resized horizontally. Is this correct? Or should I be trying to dynamically resize the svg so that the pattern scales with the container width in addition to the height? - When I zoom into the card I get a
1pxgap between thesvgelement and the card. Why is that? I've added a solid border to see what’s going on with the box model of the card. Should I make the svg slightly larger using the viewbox attribute? Am I splitting hairs here? Does this even matter? It looks fine at 100% zoom but shows up with 110%, 125%, 150%, 175%, and then disappears again at 200%.
Thanks in advance!