Figma design background not rendering in React component

I’m trying to turn a Figma design into a React component. The blue background image isn’t showing up. I’ve tried using both background and background-image attributes, but nothing works. Here’s a simplified version of my code:

const Wrapper = styled.div`
  width: 100%;
  height: 700px;
  background: url(${BackgroundImage});
  background-size: cover;
`;

const Content = () => {
  return (
    <Wrapper>
      <Section1>
        <Image src={Image1} alt="Section 1 image" />
        <Text>
          <Heading>Build Without Limits</Heading>
          <Paragraph>Some text here...</Paragraph>
          <ButtonWrapper>
            <Button>Learn More</Button>
          </ButtonWrapper>
        </Text>
      </Section1>
      <Section2>
        {/* Similar structure to Section1 */}
      </Section2>
    </Wrapper>
  );
};

Any ideas on why the background isn’t showing? Should I try adjusting z-index values? Or is there a better way to fix this?

I’ve encountered this issue before. One thing to consider is the file path for your background image. Ensure it’s correct relative to your component file. Also, if you’re using a build tool like webpack, you might need to configure it to handle image imports properly.

Another potential solution is to use the ‘react-background-image’ package. It handles background image loading and provides fallback options. You can install it via npm and use it like this:

import BackgroundImage from 'react-background-image'

const Wrapper = styled(BackgroundImage)`
  width: 100%;
  height: 700px;
`;

// In your render method:
<Wrapper src={BackgroundImage}>
  {/* Your content here */}
</Wrapper>

This approach often resolves tricky background image issues in React components.

I’ve dealt with this exact problem before, and it can be pretty frustrating. One thing that worked for me was making sure the image file was actually being imported correctly. Try console.logging the BackgroundImage variable to see if it’s the correct path.

Another trick I found helpful was setting the background-image property explicitly in the CSS, like this:

background-image: url('path/to/your/image.jpg');
background-repeat: no-repeat;
background-position: center center;
background-attachment: fixed;

This gives you more control over how the background behaves. Also, double-check that your Wrapper component is actually rendering and has the correct dimensions. Sometimes the background is there, but the container itself isn’t visible for some reason.

If none of that works, you might want to try using a regular tag as a background and positioning it absolutely within your Wrapper. It’s a bit hacky, but it can be a good fallback option.

hey there! i had a similar issue. try checking if ur BackgroundImage import is correct. also, make sure the image file exists in the right folder. if that doesn’t work, u could try using an inline style like this:

<Wrapper style={{backgroundImage: url(${BackgroundImage})}}>

hope this helps!