0

i have started just learning react js and i'm making a carousel where i want to set the picture as a bgImg putting it inside url() in a div but picturing is not getting render but when i'm puting the same in tag it is coming

import { Banners } from '../Assignment/carasoul_data'

<div className="carousel-area" style={{backgroundImage : `url(${Banners[0]})`}}>

//picture not getting render

some have suggested to use required but that also didn't worked for me

<div className="carousel-area" style={{backgroundImage: `url(${require(Banners[0])})`}} >
     </div> 

i have tried this too

"url(" + Banners[0]+ ")"

My images list which i want to render

import banner1 from'../Assignment/carasoul/Web assignment.jpeg'
import banner2 from'../Assignment/carasoul/Web assignment2.jpeg'
import banner3 from'../Assignment/carasoul/Web Banner3.jpeg'
import banner4 from'../Assignment/carasoul/Web Banner4.jpeg'

export const Banners =[banner1,banner2,banner3,banner4]

1 Answer 1

1

It is not a react error just you have to add min-height & width to your carousel css Whenever you provide empty div you have to give specific height & width therefore the image is not visible

you can try below sandbox for help

https://codesandbox.io/s/zen-kare-h6l648

Sign up to request clarification or add additional context in comments.

3 Comments

thank you so much for your response.. but i have also given height and width in the css file its just coming a blank area...and after playing arround i got to know that it is not showing .jpeg it's working fine when i use .png and in the other side .jpeg is working fine with <img src> could you please guide me what to to do
you can see my sandbox i have added jpg files only
yeahhh i'm sharing you my sendbox link please help me with my thing..i'll be greatful. codesandbox.io/s/empty-bush-e87ez1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.