Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a canvas setup with a number of particles that move around the screen. When the user clicks more particles get added. The problem is, this particle system is for a landing page.

I have the canvas working, however If I want to add text to the landing page, I can't. Is this possible? I would like to have "Welcome" in the center of the screen however if I add it into the HTML code where the particles are, It is not visible.

---My HTML---

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

---The 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;
}

I have a Codepen.io setup, ANY help is much appreciated!

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

like image 799
mp.jpeg Avatar asked Mar 12 '23 13:03

mp.jpeg


2 Answers

you can do this with 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>

see working demo

like image 112
elreeda Avatar answered May 01 '23 19:05

elreeda


If you add another element (such as an h2 or div) then you will need to give it a position:absolute and a z-index that is higher than the z-index of your #particle-js

see below html:

(notice that I added a z-index property to your #particle-js element, and I also added h2 styling below that.)

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


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

and 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;
}
like image 40
Frits Avatar answered May 01 '23 17:05

Frits