Svg sizing issue...
I am trying to do replicate a design from frontend mentors. There is a "shopping cart" svg they provided that should be in a button with "Add to Cart" text. Now, the problem is that when I put the svg next to the text, the svg appears to be massive and can't be controlled. Please help.
Button without the svg (Looks ok):
Button with the svg:
svg (shopping cart):
Please help. 🥺
13 Replies
Ohh most frustratingly, I found out that the videos on youtube showing how to build this exact UI easily handles the svg issue without any hassle!
But I have no idea what's wrong with mine...
Here...
tsbsankara
YouTube
Product Preview Card Component - Frontend Mentor Challenge
In this video we are going to build the Product Preview Card Component from Frontend Mentor. Enjoy. Please like the video and subscribe to the channel if you're not already :). Thank you.
Subscribe here: https://bit.ly/3qsAsNC
GiHub Repo: https://github.com/SankThomas/product-preview-component
Live Website: https://tsbsankara-product-preview-c...
You gotta give your SVG a height and width
The svg now is set to 15px height and 16px width
You should give it a % so it adjust itself based on it's parent, which in this case the button.
Something Like this :
Ok lemme try
Thanks a lot!
Dealing with svg is like dealing with img you have to set a width and height to them whether relative to a parent container or with Thier own height and width.
It worked!
Great
weird that it appeared so big since it has height and width declared
Yep I'm wondering too lol
https://codepen.io/MannixMD/pen/RwyMwmB it looks ok here
are you sure you used the right version/file?
you are missing the viewbox attribute in your svg
i thought about it to but why does it work in my codepen w/o it