将vue-particles组件移至背面并将其用作背景

时间:2019-04-13 15:39:05

标签: css vue.js particles.js

我希望Vue-Particles组件在后面,但是以某种方式我无法使其正常工作。我所有的组件和HTML标签都位于粒子的后面。

我尝试使用z-index CSS属性对其进行修复。

在粒子js组件上使用z-index: 0

h1 {
  z-index: 999;
}

#particles-js { 
  position: absolute;
  background-size: cover;
  top: 0; 
  bottom: 0; 
  left: 0;
  right: 0; 
  overflow-y: hidden; 
  z-index: 0;
}

显示如下:

problem 1

在粒子js组件上使用z-index: -1会将组件移到底部,而不是我想要的背景。在此处查看新问题:

Problem 2

编辑:我所有的代码都在这里,我也在使用Bootstrap-vue:


<template>
  <div id="app">
    <Navbar />
    <vue-particles color="#e60000"></vue-particles>
    <h1>Hola</h1>
  </div>
</template>

<script>
import Navbar from '../../components/Navbar.vue'

export default {
  name: 'app',
  components: {
    Navbar
  }
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;

}

h1 {
  z-index: 999;
}

#particles-js { 
  /*position: absolute;
  background-size: cover;
  top: 0; 
  bottom: 0; 
  left: 0;
  right: 0; 
  overflow-y: hidden; 
  z-index: 0;*/
  width: 100%;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 0; 
}


</style>


我想要的效果是这样的,其中的行没有覆盖标题的任何内容:

Desired effect

1 个答案:

答案 0 :(得分:2)

通过将文本div位置设置为absolute并指定垂直和水平位置,我能够重叠文本div和vue粒子。例如,将某些内容放置在屏幕中间的粒子上方:

html:

<vue-particles color="#dedede"></vue-particles>
<div class="centered-text">
  <p> Hello World </p>
</div>

css:

#particles-js {
  height: 100vh;
}

.centered-text {
  color: #ffffff;
  position: absolute;
  text-align: center;
  top: 40%;
  width: 100%;
}