The HTML button remains hidden behind a Three.js background until I bring up the Dev Tools

As I dive into my university assignment, creating a 3D scene with Three.js is both challenging and exciting. One specific requirement is to add a button that triggers the movement of one of my three vehicle objects.

However, an issue arises as I can't seem to locate the button on my page upon loading. It briefly appears against a white background before seemingly getting hidden by the JavaScript script once it loads. My goal now is to bring this elusive button to the forefront, especially since I can confirm its presence when inspecting the Dev Tool.

This mystery deepens further when I realize that opening or closing the Dev Tool command suddenly causes the button to materialize at the bottom of the page, where it remains visible. For reference, I am utilizing the VS Code live server extension in conjunction with Brave as my default browser.

Here is a snippet of what I believe to be relevant code:

<style>
    * { box-sizing: border-box }
    #container { width: 100%; height: calc(100% - 50px) }
    body {
        overflow: hidden;
    }
    #btnDrive { height: 40px; width: 25%; float: left; margin: 10px 0 0; background-color: orange; color: black; }
</style>

<body onLoad="onLoad()"> 
<div id="container"></div>
<button id="btnDrive" type="button">Drive Car</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/102/three.js"></script>
<script>
function onLoad() 
{
    const container = document.getElementById('container');
    const width = window.innerWidth, height = window.innerHeight;
    const renderer = new THREE.WebGLRenderer({ antialias: true });
    renderer.setSize(window.innerWidth, window.innerHeight);
    renderer.setClearColor(0x87ceeb);
    container.appendChild(renderer.domElement);

......</script></body>}

Answer №1

Big shoutout to @TheJim01 and @Keith for their invaluable help! I implemented the following changes in my Style section and ta-da, problem solved - now the button sits perfectly on top of my Three.js background

<style>
    * { box-sizing: border-box }
    #container { width: 100%; height: calc(100% - 50px); position: fixed; }
    body {
        overflow: hidden;
        position: absolute;
    }
    
    #btnDrive { height: 40px; width: auto; float: left; margin: 10px 0 0; background-color: orange; color: black; position: relative} 
</style>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to identify ERR_INTERNET_DISCONNECTED using a native feature within Angular 2+?

Can Angular 2+ or JavaScript help detect ERR_INTERNET_DISCONNECTED to notify the user effectively? ...

Loading 3D files in three.js is taking longer than expected

I am currently utilizing Three.js for the visualization of 3D point gene data. In addition to this project, I also have a need to showcase a "model" that has been created in 3ds format. To achieve this, I converted the 3ds file to JSON using Blender. The s ...

What is the best method to eliminate unnecessary space between controls in HTML?

Presently, I am facing the following scenario. http://jsfiddle.net/ef7vh/1/ </p> <pre> <div> <button>Button1</button> <span style="border: solid 1px black; padding: 0px 10px 0px 10px">My Text</span> < ...

Merge two arrays of the same size to create a single array of strings

Looking to merge the values of two equal-sized arrays and create a third array like the one shown below. I'm in need of guidance as I have not been able to locate a built-in JavaScript method for this specific task. The goal is to construct an array o ...

Storing items in localStorage in the same order they were added

I am having an issue with sorting localStorage items by the order they were added. Despite my code working to add items to the localStorage array and display them as HTML, I am encountering a problem with the order of the items. When I add a 3rd item to t ...

Extracting data from a website using R

I'm currently attempting to extract information such as the names, cities, states, emails, etc of professionals from the website using rvest. However, I'm facing difficulties in identifying the CSS selectors with selector gadget and it appears t ...

Strange behavior in Vue observed. The v-if directive is not properly monitoring changes

I am facing a perplexing issue. I have a basic service and a Vue component. In the template, there is a v-if directive that monitors a variable in the service (if it is true, a div should be displayed, otherwise not). Everything works fine when I initial ...

Is it possible to programmatically include a getter method to a class in JavaScript or TypeScript?

My current focus is on TypeScript and I'm exploring the decorators functionality. I would greatly appreciate some guidance or expert knowledge on JavaScript capabilities in this area. I am curious about dynamically adding a getter method to a Prototy ...

A captivating opportunity for a web developer specializing in frontend design

Encountered an intriguing dilemma that has me stumped. There is a single stipulation: Only the json can be altered! I am struggling to meet this requirement: data.hasOwnProperty("\u{0030}") class JobHunter { get data() { return &ap ...

Uploading a file using AngularJs

When it comes to uploading an image or file using HTML tag in AngularJS, it seems that the tag is not supported. The solution? Create a custom directive. In my index.html page, I included the following code: <body ng-controller="myController"> ...

Effortless floating made possible by the magic of Twitter Bootstrap

I am currently working with a group of elements that are designated as row-fluid and span12, each containing span4 elements. My goal is to have these elements automatically align in columns of 3, regardless of how many are present. However, I am facing an ...

I'm experiencing an issue with the display of my Pop Up Window

I'm currently working on a website redesign project just for fun. One issue I've encountered is with a pop-up window that appears after clicking a button. Unfortunately, the layout of the window and button is quite strange - the button is positio ...

What could be causing the issue with clicking on children of jstree not working?

I am encountering an issue with jstree. Once the data is changed, the click event does not work for every subsequent click. I find that I need to refresh the page in order to make it work. Here is a link to the jsfiddle: http://jsfiddle.net/2Jg3B/2121/ I ...

What is the best way to incorporate client and server components in nextJS when params and query parameters are required?

I'm having difficulty understanding the client/server component concept in nextJS 14 (using app router). Below is an example page illustrating how I typically structure it and what components are required: I need to extract the id value from params ...

Trouble with radio button selection in Pyppeteer, puppeteer, and Angular JS

I am struggling to select the 'fire' option in a radio button within a div element using Pyppeteer. Despite multiple attempts, I have not been successful. Here is the structure of the div with the radio button: <div _ngcontent-xqm-c396=" ...

The compatibility issues with the textarea and text-indent: placeholder feature on EDGE are causing functionality problems

I'm facing a peculiar problem with placeholders when using the Edge browser. In my current project, I need to implement a textarea with a specific text-indent property. However, on Edge, the placeholder text appears displaced more than expected. To h ...

Use jQuery to update the location.href

I am facing a challenge in changing the location.href of certain URLs on my website. These URLs are embedded in product cards and do not include the letter "a", which complicates the process. Below is the HTML code snippet in question: <div class=" ...

Meteor: Collaborative Template Sharing

Currently working on an app in Meteor that involves a rather extensive form. I've created two similar html templates - one for input and one for output, each with unique helpers. However, managing two separate templates has proven to be difficult. Is ...

Trouble with CSS styling for focused input fields

Attempting to style a form by Patriot with CSS, I encountered an issue. input#card-month:focus ~ label.card-label.label-cardExpiryYear { font-size: 20px !important; /* This works fine */ } input#card-month:focus ~ label.card-label.label-cardExpiryMont ...

What is the best way to create a Protractor test that locates the initial element within an 'ng-repeat' loop?

I am currently exploring the possibility of extracting information about the column and row position (.col, .row) of the first element/tile from the view.html code snippet provided below. <div class="container" gridster="gridsterOpts"> & ...