How to customize the font size in three.js CSS3DRenderer

I am trying to use threejs's CSS3DRenderer to display text in my 3D view. However, I am facing issues with controlling the font size. Despite setting font-size: 1px in CSS, the text remains large. I also attempted to adjust the scale of the css3dobject, but I am unsure how to calculate the scale ratio. Any help would be appreciated!

If you would like to take a look at my code, you can find it here: https://codepen.io/hungtcs/pen/xxbZOQV

import { CSS3DRenderer, CSS3DObject } from 'three/examples/jsm/renderers/CSS3DRenderer';
import { Scene, PerspectiveCamera, Mesh, PlaneGeometry, MeshPhongMaterial, Color, DoubleSide, NoBlending, WebGLRenderer, MeshBasicMaterial, GridHelper } from 'three';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';

export class CSS3DDemo {
  private scene: Scene;
  private camera: PerspectiveCamera;
  private css3DRenderer: CSS3DRenderer;
  private webGLRenderer: WebGLRenderer;
  private controls: OrbitControls;

  constructor() {
    // Code for initializing and rendering the scene goes here
  }

  private render() {
    // Code for rendering the scene continuously goes here
  }

}

Answer №1

When working with CSS3DObjects, it's important to remember that they adhere to CSS rules. For example, if you need to adjust the font size, you can easily do so by modifying the style of the div:

div.style.width = '10px';
div.style.height = '10px';
div.style.fontSize = '0.5px';

Keep in mind that in the realm of CSS3DRenderer, 1 pixel equals 1 world unit in 3D space. This means you may need to scale down your 3DObjects or reposition your camera accordingly.

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 there an Angular counterpart to Vue's <slot/> feature?

Illustration: Main component: <div> Greetings <slot/>! </div> Subordinate Component: <div> Planet </div> Application component: <Main> <Subordinate/> </Main> Result: Greetings Planet! ...

What is the best way to connect a series of checkboxes within a form utilizing Angular?

I created a form with checkboxes that allow users to select multiple options. However, when I submit the form, instead of receiving an array of objects representing the checked checkboxes, I'm not getting anything at all. Here is what I see in the co ...

How to incorporate a phone number input with country code using HTML

Can anyone help me create a phone number input field with a country code included? I've tried a few methods but haven't had much success. Here is the code I've been working with: <div class="form-group "> <input class= ...

Evaluating manually bootstrapped AngularJS applications

I've encountered an issue while testing an AngularJS application (using Karma and Jasmine) where I manually bootstrap the application in the code after some HTTP AJAX requests. angular.module("app", []); angular.element(document).ready(function() { ...

Is there a way to retrieve a comprehensive list of all anchors that contain the data-ng-click attribute

I am currently working on a web application built with asp.net and angularjs. My goal is to specifically retrieve all anchor tags that have the attribute data-ng-click assigned to them. Is there a way to achieve this? If so, how can it be done? I a ...

Utilizing an imported variable beyond a component function within React useEffect: A comprehensive guide

I'm encountering a problem while trying to utilize the imported variable likedImages within a useEffect hook in a React component. When I include likedImages in the dependency array, I receive a warning indicating that it is an unnecessary dependency ...

What are the reasons behind lang sass not functioning within the style tag of a .vue file?

Even though I had previously installed sass-loader and node-sass in my project, I encountered an issue when attempting to use <style lang="sass"> in my vue file. The style did not compile as expected, however it worked perfectly without the lang="s ...

Is it possible for me to determine when all images have finished loading in order to update the isLoaded variable to true?

I am using the template below: <template> <div v-if='isLoaded'> <div @click='selectSight(index)' v-for='(sight, index) in sights'> <img :src="'https://maps.googleapis.com/maps ...

Incomplete JSON stringification

Could someone provide insight into the reason behind this behavior? let data = JSON let date = '10-7' data['id'] = [] data['id'][date] = [[1,2,3]] data['id'][date].push([1,1,1]) console.log(data) // Outputs: { i ...

Console displaying a 400 bad request error for an HTTP PUT request

I'm currently in the process of developing a react CRUD application using Strapi as the REST API. Everything is working smoothly with the GET, DELETE, and CREATE requests, but I encounter a 400 bad request error when attempting to make a PUT request. ...

Extract a JSON substring by referencing a specific object node key

I have a JSON string that contains nested objects. Here's a portion of the JSON string: "foldChildren": "false", "branchColor": "#000000", "children": [ ...

Learn the process of assigning the present date using the jQuery UI date picker tool

I am looking to implement the feature of setting the current date using Angular/Jquery UI date picker. I have created a directive specifically for this purpose which is shown below: app.directive('basicpicker', function() { return { rest ...

What is the best way to search for a specific item in Express.js?

I recently got the Leaderboard API issue fixed, but now I'm encountering a new problem with express Querying. Specifically, I'm attempting to search for a specific Discord ID using quick.db as my database. I've included an excerpt of my expr ...

Creating regex to detect the presence of Donorbox EmbedForm in a web page

I am working on creating a Regex rule to validate if a value matches a Donorbox Embed Form. This validation is important to confirm that the user input codes are indeed from Donorbox. Here is an example of a Donorbox EmbedForm: <script src="https: ...

Having trouble loading a JavaScript file in Nuxt? Experiencing some unexpected behavior?

I have a template with HTML/CSS/JS files that I want to make dynamic using Nuxt.js. I started by copying the index.html to the Nuxt project and transferring all the necessary data to nuxt.config.js, including CSS and JS files. The page renders without erro ...

Emulate a Click Using Pure JavaScript

I am looking to add a click event to my custom dropdown, which replaces a SELECT element. The purpose of this click event is to trigger the corresponding OPTION item when an LI element is clicked. It seems like Woocommerce uses some JavaScript or PHP func ...

Retrieving a targeted data point from a JSON object

I am working with a json data that contains various properties, but I am only interested in extracting the uniqueIDs. Is there a way to retrieve ONLY the uniqueID values and have them returned to me as a comma separated list, for example: 11111, 22222? (I ...

Implementing Dynamic Lighting in Three.js: Adding and Removing Lights on the Fly

I have been working tirelessly for a few days, but I can't figure out what's wrong with my code. The lights in Three.js are not updating. Any help would be greatly appreciated to help me solve this issue. I have tried numerous combinations of th ...

Rotating and scaling an image simultaneously using CSS3

I am feeling very puzzled. Why am I unable to simultaneously scale and rotate? Despite my attempts, it seems to be not working: .rotate-img{ -webkit-transform:scale(2,2); -webkit-transform:rotate(90deg); margin-left:20%; margin-top:10%; } ...

How can you check if a field is blank without allowing any empty spaces to be saved in JavaScript?

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <html> <body> <form id="api_crud_form" name="api_crud_form" action="https://www.google.es"> Name: <input type="text" name="name" id=" ...