user16502706
user16502706

Reputation:

Add button or one div on webgl Canvas

I'm new to this topic and I have an index.html file and there I want to use three.js

this is my code :

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Test</title>
    <link rel="stylesheet" href="./style.css"></link>
  
   
</head>
<body>
    <div class="topnav">
        <a class="active" href="#File">File</a>
        <a href="#Edit">Edit</a>
        <a href="#View">View</a>
        <a href="#about">About</a>
        <canvas class="webgl"></canvas>
        <script src="../libs/three.js"></script>
        <script  src="../libs/three.min.js"></script>
        <script src="../libs/stats.min.js"></script>
        <script src="../libs/OrbitControls.js"></script>
        <script type="module" src="./main.js"></script>
      </div>

</body>
</html>

I also try this :

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Test</title>
    <link rel="stylesheet" href="./style.css"></link>
  
   
</head>
<body>
    <canvas class="webgl"></canvas>
    <script src="../libs/three.js"></script>
    <script  src="../libs/three.min.js"></script>
    <script src="../libs/stats.min.js"></script>
    <script src="../libs/OrbitControls.js"></script>
    <script type="module" src="./main.js"></script>
    <div class="topnav">
        <a class="active" href="#File">File</a>
        <a href="#Edit">Edit</a>
        <a href="#View">View</a>
        <a href="#about">About</a>
      </div>

</body>
</html>

and my css file :

* {
  margin: 0;
  padding: 0;
}

html,
body {
  overflow: hidden;
}

.topnav {
  overflow: hidden;
  background-color: #333;
}

.topnav a {
  float: left;
  color: #f2f2f2;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size: 17px;
}

.topnav a:hover {
  background-color: #ddd;
  color: black;
}

.topnav a.active {
  background-color: #04aa6d;
  color: white;
}

.webgl {
  position: fixed;
  top: 0;
  left: 0;
  outline: none;
}

My problem is that div for menubar didn't show in front of the canvas.

what should I do?

Thanks.

Upvotes: 0

Views: 339

Answers (1)

sebastian.zawolanski
sebastian.zawolanski

Reputation: 172

Transform your HTML into something like below:

<div class="topnav">
  <a class="active" href="#File">File</a>
  <a href="#Edit">Edit</a>
  <a href="#View">View</a>
  <a href="#about">About</a>
</div>
<canvas class="webgl"></canvas>
<!-- script tags -->

then remove position, left and top properties from webgl class.

Upvotes: 1

Related Questions