CSS Grid将主页分为两部分

问题描述 投票:0回答:2

在CSS网格布局上遇到一些麻烦。我在课堂上使用了网格简介,它将我的粒子和引言段分成两部分。

我想要的是粒子覆盖整个100vh的背景

这是一个小提琴:

Notice in the fiddle, my particles arent in the background

JS Fiddle

css css-grid particles.js
2个回答
1
投票

您需要将段落标记移动到粒子之外。所以你的HTML会是这样的

  <div class="headerdata">      
        <p id="Introduction" class="css-typing">
            Hi, I'm <strong>Billy Bob</strong>.
        <br/><br/>
            I'm a <strong>front-end</strong> and <strong>back-end</strong> developer.
        </p>
  </div>
    <header id="particles-js">
    </header>

你的CSS就像

.headerdata {
    height:100vh;
    background-color:#030711e8;
    position: absolute;
    padding-top: 60px;
    width:100%;
}
header{
  position:absolute; width: 100%; 
  height: 100%;  
  background-repeat: no-repeat; 
  background-size: cover; 
  background-position: 50% 50%; 
} 

https://jsfiddle.net/nimittshah/gLq56ptv/


0
投票

我记得有类似颗粒的问题。如果你想让粒子成为你的整个背景,这是我的解决方案:

  • 你不应该将所有内容包装在粒子div中,粒子div应该被关闭
  • 在粒子应该是包含所有内容的div之后,它应该具有相对位置和比粒子大的z-index。 Prticles的位置应该是固定的。基本上,你的html结构看起来像这样:

.overlay {
   z-index: 100;
   position: relative;
}
#particles-js {
    position: fixed;
    height: 100%;
    width: 100vw;
    z-index: 0;
    display:grid;
    height:100vh;
    background-color:#030711e8;
}
<body>
    <div id="particles-js"></div>
    <div class="overlay">
        <p>  your introduction  </p>
        <main>  your content  </main>
    </div>  
</body>
© www.soinside.com 2019 - 2024. All rights reserved.