可以将HTML内容放在画布上(登录页)

Possible to put HTML Content on top of a Canvas (Landing Page)

本文关键字:登录 HTML      更新时间:2023-09-26

我有一个画布设置,其中有许多粒子在屏幕上移动。当用户单击时,会添加更多粒子。问题是,这个粒子系统是用于登录页的。

我有画布在工作,但是如果我想向登录页添加文本,我不能。这可能吗?我希望屏幕中央有"欢迎",但是如果我把它添加到粒子所在的HTML代码中,它是不可见的。

---我的HTML---

<div id="particles-js"></div>
<div class="count-particles">
  <span class="js-count-particles">--</span> particles
</div>

---CSS——

/* ---- reset ---- */
body {
  margin: 0;
  font:normal 75% Arial, Helvetica, sans-serif;
}
canvas {
  display: block;
  vertical-align: bottom;
}
/* ---- particles.js container ---- */
#particles-js {
  position: absolute;
  width: 100%;
  height: 100%;
  background-color: blue;
  background-image: url("");
  background-repeat: no-repeat;
  background-size: cover;
  background-position: 50% 50%;
}
/* ---- stats.js ---- */
.count-particles{
  background: #000022;
  position: absolute;
  top: 48px;
  left: 0;
  width: 80px;
  color: #13E8E9;
  font-size: .8em;
  text-align: left;
  text-indent: 4px;
  line-height: 14px;
  padding-bottom: 2px;
  font-family: Helvetica, Arial, sans-serif;
  font-weight: bold;
}
.js-count-particles{
  font-size: 1.1em;
}
#stats,
.count-particles{
  -webkit-user-select: none;
  margin-top: 5px;
  margin-left: 5px;
}
#stats{
  border-radius: 3px 3px 0 0;
  overflow: hidden;
}
.count-particles{
  border-radius: 0 0 3px 3px;
}

我有一个Codepen.io设置,非常感谢任何帮助!

-Codepen.io-http://codepen.io/HoneyBadgerYT/pen/jqKZxo

您可以使用css 来完成此操作

h1 {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
}

html:

<div id="particles-js"></div>
<h1>Welcome</h1>
<div class="count-particles">
  <span class="js-count-particles">--</span> particles
</div>

请参阅的工作演示

如果添加另一个元素(如h2或div),则需要给它一个position:absolute和一个高于#particle-jsz-indexz-index

参见以下html:

(请注意,我为#particle-js元素添加了一个z-index属性,并在其下方添加了h2样式。)

<div id="particles-js"></div>
<h2>WELCOME</h2>
<div class="count-particles">
  <span class="js-count-particles">--</span> particles
</div>

和CSS

/* ---- reset ---- */
body {
  margin: 0;
  font:normal 75% Arial, Helvetica, sans-serif;
}
canvas {
  display: block;
  vertical-align: bottom;
}
/* ---- particles.js container ---- */
#particles-js {
  position: absolute;
  width: 100%;
  height: 100%;
  background-color: blue;
  background-image: url("");
  background-repeat: no-repeat;
  background-size: cover;
  background-position: 50% 50%;
  z-index:1;
}
h2 {
  position:absolute;
  z-index:2;
  width:100%;
  text-align:center;
  color:#ffffff;
  top:0;
  left:0;
}
/* ---- stats.js ---- */
.count-particles{
  background: #000022;
  position: absolute;
  top: 48px;
  left: 0;
  width: 80px;
  color: #13E8E9;
  font-size: .8em;
  text-align: left;
  text-indent: 4px;
  line-height: 14px;
  padding-bottom: 2px;
  font-family: Helvetica, Arial, sans-serif;
  font-weight: bold;
}
.js-count-particles{
  font-size: 1.1em;
}
#stats,
.count-particles{
  -webkit-user-select: none;
  margin-top: 5px;
  margin-left: 5px;
}
#stats{
  border-radius: 3px 3px 0 0;
  overflow: hidden;
}
.count-particles{
  border-radius: 0 0 3px 3px;
}