-1

This is my code and somehow I am not able to get the image loaded.

import React from 'react'
import styled from "styled-components"


function Section() {
  return (
    <Wrap>
      
    </Wrap>
  )
}

export default Section

const Wrap = styled.div`
  width: 100vw;
  height: 100vh;
  background-image: https://drive.google.com/file/d/1rMeRfE2OEktMOGVlgA1TwJKNj1teuLtG/view?usp=sharing;
`

What should I do?

Lin Du
  • 88,126
  • 95
  • 281
  • 483
  • You should look at the [syntax for a CSS background-image rule](https://developer.mozilla.org/en-US/docs/Web/CSS/background-image). – ray Mar 08 '22 at 03:35
  • Does this answer your question? [Displaying files (e.g. images) stored in Google Drive on a website](https://stackoverflow.com/questions/10311092/displaying-files-e-g-images-stored-in-google-drive-on-a-website) – jsN00b Mar 08 '22 at 03:48

3 Answers3

1

For the direct link of an image stored in Google Drive:

https://drive.google.com/uc?export=view&id=file's ID

So the URL of your image should be:

https://drive.google.com/uc?export=view&id=1rMeRfE2OEktMOGVlgA1TwJKNj1teuLtG.

Then, use it via CSS background-image: url('https://drive.google.com/uc?export=view&id=1rMeRfE2OEktMOGVlgA1TwJKNj1teuLtG')

See, Displaying files (e.g. images) stored in Google Drive on a website

Lin Du
  • 88,126
  • 95
  • 281
  • 483
0

When you use background-image, you should use url() with URL.

ref: https://developer.mozilla.org/en-US/docs/Web/CSS/background-image

const Wrap = styled.div`
  width: 100vw;
  height: 100vh;
  background-image: url("https://drive.google.com/file/d/1rMeRfE2OEktMOGVlgA1TwJKNj1teuLtG/view?usp=sharing");

Edit

Your Url is not Image so you can not load image with your Google Drive Url.

kyun
  • 9,710
  • 9
  • 31
  • 66
0

You have set the wrong value for the CSS property.

✓ Use This:

background-image: url("https://drive.google.com/file/d/1rMeRfE2OEktMOGVlgA1TwJKNj1teuLtG/view?usp=sharing");

✘ Instead of your this code:

background-image: https://drive.google.com/file/d/1rMeRfE2OEktMOGVlgA1TwJKNj1teuLtG/view?usp=sharing;

As in your current question I see you have forgotten to put url().

udoyhasan
  • 1,527
  • 5
  • 19