Having trouble aligning the canvas of threejs next to a div

I am currently working on a shoe customizer project and facing difficulties in aligning my canvas (using three.js) next to the shoe customizer div. Although I posted the same question earlier, I did not receive a satisfying solution. I made some adjustments based on the responses, but now the canvas appears on top of the div instead of beside it. Please assist.

Main concern: How can I position my canvas-container next to the customizer-container?

HTML

  
<body>
    <img class="logo-image" src="/public/SWEAR-logo.png" alt="SWEAR logo">
    <div class="wrapper">
      <div class="canvas-container"></div>
        <div class="customizer-container">
          <img id="close-window" src="/public/close.png" alt="close-window">
          <h1 id="name"></h1>
          <div class="color-palette-container">
                <p>Colors</p>
                <div id="color-palette-laces">
                    <div><div class="box red" style="background-color: red;"></div> Red </div>
                    <div><div class="box green" style="background-color: green;"></div> Green </div>
                    <div><div class="box blue" style="background-color: blue;"></div> Blue </div>
                    <div><div class="box yellow" style="background-color: yellow;"></div> Yellow </div>
                    <div><div class="box purple" style="background-color: purple;"></div> Purple </div>
                    <div><div class="box pink" style="background-color: pink;"></div> Pink </div>
                </div>

                <!-- More color palette elements here -->

                <p>Fabrics</p>
                <div id="color-fabrics-laces">
                    <div><div class="box-fabric plastic" style="background-color: red;"></div> Plastic </div>
                    <div><div class="box-fabric metallic" style="background-image: url('/textures/metallic.jpg');"></div> Metallic </div>
                    <div><div class="box-fabric polyester" style="background-image: url('/textures/polyester.jpg');"></div> Polyester </div>
                    <div><div class="box-fabric leather" style="background-color: yellow;"></div> Leather </div>
                </div>
              </div>

              <!-- Size container element -->

            <button id="orderButton" disabled>Order now</button>
        </div>
      </div>
    <script type="module" src="/main.js"></script>
  </body>

CSS

body {
  margin: 0;
  text-align: center;
  font-family: 'Helvetica', sans-serif;
  text-transform: uppercase;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.wrapper {
  display:flex;
  width: 100%;
}

.customizer-container {
  width: 500px; 
  height: 100vh;
  background-color: black;
  color: white;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.canvas-container {
  flex: 1;
  height: 100vh;
  position: relative;
}

Javascript

const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
const canvas = document.querySelector('.canvas-container');
canvas.appendChild(renderer.domElement);

Current Layout: View Image Here

Currently, both elements are stacked on top of each other. My goal is to have them positioned side by side with the canvas on the left and the customizer on the right without compressing the canvas element.

Link to complete code: Project Repository

Answer №1

take a look at this

body {
      margin: 0;
      text-align: center;
      font-family: 'Helvetica', sans-serif;
      text-transform: uppercase;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
    }

    .wrapper {
      display: flex;
      width: 100%;
    }
    
    .canvas-container, .customizer-container {
      width: 50%;
      height: 100vh;
      position: relative;
    }

    .customizer-container {
      background-color: red;
      color: white;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
     }

    .canvas-container {
      flex: 1;
      height: 100%;
      position: relative;
    }
    .color-palette-container,
    .size-container {
      margin-top: 20px;
    }

    .size-container {
      margin-top: auto;
      margin-bottom: 20px;
    }
    #orderButton {
      margin-top: 20px;
      margin-bottom: 20px;
    }
<div class="wrapper">
    <div class="canvas-container"></div>
    <div class="customizer-container">
      <h1 id="name">Customizer</h1>
      <div class="color-palette-container">
        <p>Colors</p>
        <!-- Color palettes go here -->
      </div>
      <div class="color-palette-container">
        <p>Fabrics</p>
        <!-- Fabric options go here -->
      </div>
      <div class="size-container">
        <label for="size">Size</label>
        <select name="size" id="size">
          <option value="" disabled selected>Select</option>
          <option value="size-36">36</option>
          <option value="size-37">37</option>
          <option value="size-38">38</option>
          <option value="size-39">39</option>
          <option value="size-40">40</option>
          <option value="size-41">41</option>
          <option value="size-42">42</option>
        </select>
      </div>
      <button id="orderButton" disabled>Order now</button>
    </div>
  </div>

  <script type="importmap">
  {
    "imports": {
      "three": "https://unpkg.com/linktothreejs/build/three.module.js",
      "three/addons/": "https://unpkg.com/linktoaddons/examples/jsm/"
    }
  }
</script>

  <script type="module">
    import * as THREE from 'three';
    import { OrbitControls } from 'three/addons/controls/OrbitControls.js';

    const scene = new THREE.Scene();
  const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
  const renderer = new THREE.WebGLRenderer();
  renderer.setSize(window.innerWidth, window.innerHeight);
  const canvasContainer = document.querySelector('.canvas-container');
  canvasContainer.appendChild(renderer.domElement);

  const icosahedronGeometry = new THREE.IcosahedronGeometry(1, 0);
  const diamondMaterial = new THREE.MeshStandardMaterial({ color: 0x00FFFF });
  const diamond = new THREE.Mesh(icosahedronGeometry, diamondMaterial);
  diamond.position.x = -3;
  scene.add(diamond);

  const controls = new OrbitControls(camera, renderer.domElement);
  controls.enableDamping = true;
  controls.enabled = true;

  const dL = new THREE.DirectionalLight(0xFFFFFF, 1);
  dL.position.set(1, 1, 1).normalize();
  scene.add(dL);

  camera.position.z = 5;

  const rotationSpeed = 0.002;

  function animate() {
    requestAnimationFrame(animate);
    diamond.rotation.x += rotationSpeed;
    diamond.rotation.y += rotationSpeed;
    controls.update();
    renderer.render(scene, camera);
  }

  animate();

  window.addEventListener('resize', () => {
    const newWidth = window.innerWidth;
    const newHeight = window.innerHeight;
    camera.aspect = newWidth / newHeight;
    camera.updateProjectionMatrix();
    renderer.setSize(newWidth, newHeight);
  });
  </script>

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

I am facing an issue where the HTML button is not properly interacting with the JavaScript function

function idk() { let cypher = {A:"G",B:"L",C:"Z",D:"E",E:"Y",F:"R",G:"D",H:"N",I:"K",J:"W",K:"J",L:"B",M:"Q",N:"F",O:"S",P:"C",Q:"V",R:"X",S:"I",T:"O",U:"M",V:"T",W:"A",X:"U",Y:"H",Z:"P"}; var answer = prompt('What cypher are you going to use 1 - 26& ...

Utilizing Vue.js to create a secondary navigation by transforming a select dropdown and integrating tabs simultaneously

After successfully setting up a tabs navigation using Vue with the help of a previous question HERE, I now have a working code for the tabs navigation as shown below: <ul> <c:forEach items="${tabnav.tabs}" var="tab" varStatus="loop"> <c:i ...

Making an HTTP request using AngularJS takes significantly more time than directly accessing the endpoint through a web browser

I'm currently working on improving the functionality of a WordPress website using AngularJS. To achieve this, I am utilizing the WP-API (v2) plugin to create custom endpoints and consuming them on the front end with the Angular $http service. Below i ...

Struggling to generate a TrackballControls instance

Every time I try to create a TrackballControls object, I encounter an error message stating "THREE.TrackballControls is not a constructor". Here's a simple example: <!doctype html> <html> <head> <title>Trackball Contr ...

Using arrow functions in node.js

Can someone help me understand how arrow functions work? I know that arrow functions are typed like this () =>, but I'm curious about how the function that contains the arrow function knows how to call it. For example: app.listen(3000 , () => ...

Not all dynamic content is loaded through Ajax requests on a single domain

I currently have my domain forwarded (cloaked) to The main page (index.html) utilizes Ajax for loading content. All content loads properly at the original host (moppy.co.uk/wtcdi). However, on the forwarded domain (whatthecatdragged.in), some content fai ...

"Trouble with Angular JS foreach loop: only the final item in the array

Struggling to loop through each item object in a JSON data set and evaluate its value using angular.forEach(). However, only the last item is being returned, making it impossible to perform any meaningful evaluation. Oddly enough, when using console.log(), ...

Advanced Techniques: Leveraging Master Layouts, Partial Rendering, and JavaScript Function

Trying to understand the sequence of events when a master page, partials, and JavaScript code are involved. Imagine having a Master page with scripts: <%@ Master Language="C#" ... %> <head> <asp:ContentPlaceHolder ID="HeadContent" run ...

Tips for manipulating rows in HTML using jQuery when the id attribute is added

Apologies in advance for any language errors in my explanation I am working on an input table where each row has a unique ID, and the input in each row affects the next row. As new rows are added, I have implemented an incremental numbering system for the ...

Could anyone please provide advice on how to resolve the issue I encountered when trying to make Post and get Http method calls using protractor?

I am currently facing an issue while trying to make a GET API request using protractor. The challenge lies in using the bearer token generated from a previous POST response in the headers of the GET request. Although I have successfully executed the POST r ...

What is the procedure for altering the location of a mesh within the animate() function in three.js?

In my implementation of a three.js mesh (found in three.js-master\examples\webgl_loader_collada_keyframe.html), I have a basic setup: function init() { ... ... var sphereGeometry = new THREE.SphereGeometry( 50, 32, 16 ); var sphereMater ...

Is there a method available to streamline the process of generating .json files for language translations?

Working with translation files can be a tedious task, especially when adding new keys for different languages. Making sure that each key is included in all the JSON files can lead to errors and repetitive editing. Is there a more efficient way to handle t ...

React and Redux experiencing issues with rendering the view

Currently, I am in the process of creating a compact bookkeeping application using React and Redux. However, I am facing an issue where the view is not rendering, and there are no errors being displayed in the code. Let's take a look at the structure ...

Resolving the bothersome complications of self-looping steps in jQuery animate delay

My timeline definition includes selectors and a sequence of delays and animations to apply to an object. I have also provided the option to loop through the steps for a specific object. Here is the function that I use to queue the animations: function an ...

Issue: When calling setState(...), you must provide either an object containing the state variables to update or a function that will return an object with the updated

Encountering an error in the else section with this.state.incorrect + 1 and this.state.correct + 1 I've come across a similar issue that wasn't resolved by visiting this link: React Native: setState(...): takes an object of state variables to up ...

The Concept of Interface Segregation Principle within jQuery

Could someone provide a clear explanation of how this function operates using jQuery? Especially in reference to the response found here. It seems similar to the Single Responsibility Principle (SRP) in Object-Oriented Programming. What sets it apart? ...

Utilize Aframe to easily view and upload local gltf files

I've been working on a project to create a user-friendly panel for loading and viewing gltf models in real-time in A-frame. Here is the current workflow I am following: Using the input tag to load files from local storage. Using v-on-change to assi ...

Unable to load images on website

I'm having trouble showing images on my website using Node.js Express and an HBS file. The image is not appearing on the webpage and I'm seeing an error message that says "GET http://localhost:3000/tempelates/P2.jpg 404 (Not Found)" Here is the ...

Generating custom reports based on specific data fields

My current approach involves displaying all the columns for the searched records in a div with the id of searchresults using AJAX. I then provide a print option to print those records. However, I now want to enhance this functionality by allowing users to ...

Building a family tree with JavaScript's Document Object Model

My goal is to use jQuery to construct the following DOM setup: <li> <label> user <input type=radio> </label> </li> Below is the jQuery code I am trying to use. $('<input>') .attr({type:'radio&ap ...