【发布时间】:2020-10-30 15:53:13
【问题描述】:
如您所见,包含粒子的 div 和 Home 组件仅使用了 3/4 的高度,即使 height 属性为 100%。我渲染组件是否错误,我应该怎么做才能使组件填满整个页面。
我认为问题出在 ParticlesComponent 因为某种原因它没有占用全部可用宽度。
App.js:
return (
<div
style={{
position: "absolute",
top: 0,
left: 0,
width: "100%",
height: "100%"
}}
>
<ParticlesComponent />
<div
style={{
position: "absolute",
top: 0,
left: 0,
width: "100%",
height: "100%"
}}
>
<Home/>
</div>
</div>
);
}
export default App;
粒子组件:
export default () => (
<div
style={{
position: "absolute",
top: 0,
left: 0,
width: "100%",
height: "100%",
backgroundSize: "cover",
backgroundPosition: "50% 50%"
}}
>
<Particles
// unrelated particle code that I decided to remove so that it doesn't clog up the page
/>
</div>
);
更新
我是怎么解决的
我将此添加到 index.html 文件中:
#tsparticles{
width: 100%;
height: 100%;
position: fixed;
background-image: url('');
background-size: cover;
background-position: 50% 50%;
background-repeat: no-repeat;
}
.body-particles{
position: absolute;
top: 0;
left: 0;
z-index: 100;
}
【问题讨论】:
-
您只设置了父容器的高度。您是实际上使用
particle.js,还是使用react-particles-js?您能否更新您的问题以包含ParticlesComponent组件代码? -
由于您只提供了一张图片,因此很难理解我们的案例中出了什么问题。你能分享一下实际的网站或代码库吗?
-
@DrewReese 是的,我正在使用 react-particles-js。我添加了代码。是不是粒子组件中div的样式不对?
-
@Constantin 嗨,很抱歉,我刚刚在 GitHub 上添加了完整的代码库:github.com/TanushN/portfolio。任何帮助将不胜感激。
标签: javascript html css reactjs react-particles-js