我正试图在我的Reaction项目中添加一个背景图像,但它没有显示,尽管有正确的相对路径作为URL. 这是我的"App.js":
import "./styles.css";
export default function App() {
return (
<div className="App">
<h1>Hi All!</h1>
<h2>Please guide why the background image isn't showing here???</h2>
</div>
);
}
下面是"style es.css":
.App {
font-family: sans-serif;
text-align: center;
background: aqua;
height: 100vh;
background-image: url(./images/img-2.jpg);
/* background-image: url(https://pixabay.com/photos/dandelion-seeds-dew-dewdrops-445228/); */
background-size: cover;
background-repeat: no-repeat;
}
下面是代码沙箱的例子:https://codesandbox.io/s/festive-scott-h28j42?file=/src/styles.css:0-294