我一直试图将背景图片添加到我的网页中。这是我目前正在尝试执行的操作,但似乎没有用。
在我的App.js文件中:
import React from 'react';
import './App.css';
import NavBar from './Components/NavBar';
import LandingPageImage from './Components/LandingPageImage';
function App() {
return (
<div className="App">
<div className="Screen" >
<NavBar/>
<LandingPageImage/>
</div>
</div>
);
}
export default App;
在我的App.css文件中:
.Screen {
background-image: url("https://images.unsplash.com/photo-1536514498073-50e69d39c6cf?ixlib=rb-1.2.1&auto=format&fit=crop&w=1951&q=80");
}
这似乎不起作用。我原本希望在Screen div上看到背景图片,但什么都没显示。
答案 0 :(得分:0)
代码正确。我认为您的<Navbar />
和<LandingPageComponent />
拥有自己背景的整个div,因此您看不到它。
尝试向div中添加一些文本,以查看其是否正常工作。
import React from 'react';
import './App.css';
import NavBar from './Components/NavBar';
import LandingPageImage from './Components/LandingPageImage';
function App() {
return (
<div className="App">
<div className="Screen" >
<NavBar/>
<LandingPageImage/>
Text to give additional height to div.
</div>
</div>
);
}
export default App;