SVG as background image to fill entire container

Hi, I’m trying to get this image which was saved as an SVG to fill the entire background, I’ve tried setting the background size to cover/contain but still won’t work. Here’re the CSS code .testimonial-section { background-image: url(images/bg-curve-desktop.svg); background-repeat: no-repeat; background-size: 100% 100%; background-position: center; background-color: orange; } Here’s what I get And here’s what I’m trynna achieve
16 Replies
croganm
croganm11mo ago
What does the svg code look like? See link for why
croganm
croganm11mo ago
Stack Overflow
Background cover is not working correctly
I have a problem : the svg bar isnt responsive (see picture), anyone maybe has a solution for that? I seriously searched for around 1 1/2 hour now and im getting really frustrated :/ Here is my co...
ucheszona
ucheszona11mo ago
@croganm it’s a picture and not really a code. It’s a challenge from frontendmentor
croganm
croganm11mo ago
SVG is actually code if you open it in your editor (whether VSCode or whatever) 🙂 ^
ucheszona
ucheszona11mo ago
I understand you but I mean this one came in a form of an image just like icons and illustration pictures
croganm
croganm11mo ago
You wouldn't be able to open it at all in an editor? I mean I know they are images but they're images made up out of code and everything. It's how we can edit them. The issue is that a lot of SVG's have built in height and widths on them, which makes them pretty inflexible for situations like background images. We would just likely need to delete those attributes and replace it with a viewBox attribute if none exists This way we can morph it
ucheszona
ucheszona11mo ago
Oh, I’ll need you to share and example if you don’t mind, cause it’s really making me think tirelessly
croganm
croganm11mo ago
So this image
croganm
croganm11mo ago
croganm
croganm11mo ago
Really is just the following code:
<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd"><path d="M22 22h1v2h-22v-2h1v-8h20v8zm-7-5h-6v6h2v-5h2v5h2v-6zm-9 3h-2v2h2v-2zm14 0h-2v2h2v-2zm-14-4h-2v2h2v-2zm14 0h-2v2h2v-2zm4-3h-24l3-7h3.943l-2.601 2.229.66.771 5.998-5.143v-3.857h5l-1 1.491 1 1.509h-4l6.999 6 .661-.771-2.602-2.229h3.942l3 7zm-12-6.5c1.38 0 2.5 1.12 2.5 2.5s-1.12 2.5-2.5 2.5-2.5-1.12-2.5-2.5 1.12-2.5 2.5-2.5zm0 2.5h1v.8h-1.763v-1.8h.763v1z"/></svg>
<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd"><path d="M22 22h1v2h-22v-2h1v-8h20v8zm-7-5h-6v6h2v-5h2v5h2v-6zm-9 3h-2v2h2v-2zm14 0h-2v2h2v-2zm-14-4h-2v2h2v-2zm14 0h-2v2h2v-2zm4-3h-24l3-7h3.943l-2.601 2.229.66.771 5.998-5.143v-3.857h5l-1 1.491 1 1.509h-4l6.999 6 .661-.771-2.602-2.229h3.942l3 7zm-12-6.5c1.38 0 2.5 1.12 2.5 2.5s-1.12 2.5-2.5 2.5-2.5-1.12-2.5-2.5 1.12-2.5 2.5-2.5zm0 2.5h1v.8h-1.763v-1.8h.763v1z"/></svg>
Notice that width and height attribute? You can usually ignore that, but for background images, it's a bit tougher If we delete those attributes, you can size it according to whatever and the SVG will adjust Also, if you don't mind me asking, what's the exact image you're having issues with. I see that orange and blue in your example that's not in the version you're trying to recreate
ucheszona
ucheszona11mo ago
I’m trynna recreate the one with the plain white color but I just don’t know how to go about this cause the image didn’t come with any SVG code , it only came just like a normal photo would, just like an illustration also. Sorry if I’m stressing you out and I appreciate the fact that you trynna help out
croganm
croganm11mo ago
Yea no problem at all. Do you have an example of the site you could show? I know it's a frontend mentor challenge as I've done them myself, but could you drag the folder into this site and send the link? https://app.netlify.com/drop/do
Netlify App
Start building the best web experiences in record time
ucheszona
ucheszona11mo ago
Okay thank, will do that right now
Oladapo Elijah
Oladapo Elijah11mo ago
I am facing the same issue, but I haven't found a solution for it yet. If you have managed to resolve it, could you please share how you handled it? Thanks!
croganm
croganm11mo ago
Yes, I helped him solve it via DM. Unless you have exactly the same project and the exact same problem, I'd recommend creating a new post or DMing me This was a specific case
Oladapo Elijah
Oladapo Elijah11mo ago
Okay.. I will send you a direct message.