简体   繁体   中英

How to put background image React?

I need your help. I am trying to set background image for my header. Photo is in the "public" folder. I prescribe the way to my photo in css. But i have a mistake. What i am doing wrong? How to set the background image in React?

Css

.header{
width: 100%;
height: 550px;
background-image: url(./public/one.jpg);
}

Js

import React from "react";

export let Header = () => {
return <header className='header'>
</header>
}

seems like you're in the src folder, so you'll need to go to the parent directory in order to get to the public folder, like this: "../public/one.jpg" instead of "./public/one.jpg" .

I would recommend to add an asset folder within src, instead of using the public folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM