javascript - Reactjs 背景图像仅在有组件的地方显示
问题描述
我正在尝试为我的网站制作全屏背景图像,但它似乎不起作用。我当前的代码只显示了渲染组件的背景图像部分。我曾尝试background-position: fixed
在 App.css 文件中使用,但背景图像变成全屏但我无法滚动,这更糟糕。我怎样才能让它工作?
我的网站现在的样子:
我试图设置min-width: 100vw
,min-height: 100vh
但现在网页顶部仍然有同样的问题,网页变得可滚动。
编辑的网页:
下面分别是我的 App.js 和 App.css 的文件。
class App extends Component {
componentDidMount() {
this.props.onAuthCheck();
}
render() {
const auth = this.props.token !== null;
return (
<BrowserRouter>
<div className="App">
<Route path="/" exact component={Login} />
<Route path="/signup" exact component={SignUp} />
<GuardedRoute
path="/home"
component={Home}
auth={auth}
exact
/>
<GuardedRoute
path="/stocks"
component={Stocks}
auth={auth}
exact
/>
<GuardedRoute
path="/News"
component={News}
auth={auth}
exact
/>
<GuardedRoute
path="/profile"
component={Profile}
auth={auth}
exact
/>
<GuardedRoute
path="/your-analysis"
component={YourAnalysis}
auth={auth}
exact
/>
<GuardedRoute
path="/create-analysis"
component={CreateAnalysis}
auth={auth}
exact
/>
</div>
</BrowserRouter>
);
}
}
.App {
background-image: url('./assets/login-bg.jpg');
min-width: 100%;
min-height: 100%;
background-size: cover;
background-position: center center;
background-attachment: fixed;
list-style: none;
}
解决方案
尝试这个:
.App {
background-image: url('./assets/login-bg.jpg');
min-width: 100%;
min-height: 100vh;
background-size: cover;
background-position: center center;
background-attachment: fixed;
list-style: none;
}
或者您可以将背景图像设置为<body>
推荐阅读
- python - re.findall... 发现太多了!:)
- sql - 根据同一表中特定记录的计数更新表
- java - 实施调平系统的标准做法,其中每个级别都会解锁新的东西
- python - python中n个自然数的倒数之和
- python - 无法在 Python 中的 Beautiful Soup 中抓取 div 标签,
- prolog - Prolog:我怎样才能只显示伴随某些数字的名字。我在序言中有一个列表,我只需要显示几个特定的名字
- python - 点子没更新?如何找到用户?
- python - 如何处理 Python Numpy 中的精度问题?
- javascript - 回调箭头函数不会从它的父函数继承“this”**这不是重复的**
- arrays - 尝试在 C 中创建打字效果