Is there a way to showcase the output of the <div id="height"> on the height of the rectangle?

My Current Project

Currently, I am in the process of developing a picture framing calculator using a combination of HTML, CSS, and JavaScript.

Functionality of the Calculator

For this calculator, users will input values such as:

    Frame Width (wf):  16
    Frame Height (hf):  20 
    Picture Width (wp): 11 
    Picture Height (hp): 17
    Mat Overlap (o): .25

The equations utilized in the functionality are as follows:

  1. Width = (1 / 2) * (hf - hp + o) = 1.625 which corresponds to the <div id="width">

  2. Height = (1 / 2) * (wf - wp + o) = 2.625 which corresponds to the

    <div id="height">

The Styling Code

* {
  margin: 0;
  padding: 0;
  font-family: 'Lato', sans-serif;
}

/* Additional CSS Code Here... */
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8>
  <link rel="stylesheet" href="style.css">
  <title>Framing Calculator</title>

  <!-- HTML & JavaScript Code Here -->

Current Issue & Attempts

Although I have successfully displayed the Width value in the rectangle, I am encountering difficulties with displaying the Height value. This snippet of code is where the issue lies:

<center><div style="width:300px;height:400px;border:1px solid #000;"><center><div id="width"><div id="height"></div></center></div></center>

My Inquiry

  1. How can I properly showcase the
    <div id="height">
    as illustrated in this image? In the image, the calculated value of 1.625 is correctly displayed in the <div id="width">.

Answer №1

After much deliberation, I have finally cracked the code to the following query:

How can I showcase the design as illustrated in the image here, including the placement of Cut Height and Cut Width?

To achieve this, I inserted a div with the id of height into the rectangle:

<center>
  <div style="width:200px;height:300px;border:1px solid #000;">
    <center>
      <div id="width"></div>
    </center>
    <div id="height"></div>
  </div>
</center>

Subsequently, I applied the following CSS:

#height {
  text-align: left;
  margin-top: 130px;
  margin-left: 4px;
}
  1. To start, I aligned the text to the left side of the rectangle.
  2. Then, I shifted the rectangle downwards by 130 pixels, approximately half of the 300px tall box (instead of using 150px, exactly half, to prevent the text from being centered at the top of the box).
  3. Lastly, I added a 4px left margin to create some distance between the text and the left edge for a less cramped appearance.

Furthermore, I have introduced calculated values displayed in the width and height sections of the shape on a rectangle, based on the input from a picture framing calculator. You can view the results here.


Decimal to Fraction - Optional

UPDATE: Upon conducting further research, I stumbled upon a method to showcase the output in fraction form rather than decimal.

First Amendment for Fractions

To implement this in the initial HTML code:

Locate:

<input type="button" onclick="calc()" value="Calculate" name="cmdCalc"/>
</fieldset>
</form>
</section>

Insert After:

<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="107662717364797f7e717c50213e203e20">[email protected]</a>/index.js"></script>

I stumbled upon a library called fraction.js. You can load fraction.js via the unpkg.com platform.


Second Amendment for Fractions

Locate:

document.getElementById('width').innerHTML = width;
document.getElementById('height').innerHTML = height;

Replace With:

document.getElementById('width').innerHTML = new Fraction(width).toString();
document.getElementById('height').innerHTML = new Fraction(height).toString();

Instead of simply using width, I opted for new Fraction(width).toString() as advised in the documentation of the library to convert decimals into fractions.

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

My JavaScript/jQuery code isn't functioning properly - is there a restriction on the number of api calls that can be made on

Below is the code I have implemented from jquery ui tabs: <script> $(function(){ // Tabs $('#tabs1').tabs(); $('#tabs2').tabs(); $('#tabs3').tabs(); //hover states on the sta ...

Restrict the quantity of items retrieved from an AJAX response

An AJAX call has returned a response consisting of a list of <a> elements: <a href="/1/">One</a> <a href="/2/">Two</a> <a href="/3/">Three</a> I am looking to select only the first n a elements from this response ...

Navigate directly to a specific section on a webpage

Check out these different links: <a class="faq_text_header_jump" href="#general_questions">Questions About General Topics</a><br> <a class="faq_text_header_jump" href="how_to_use_platform">How to Use the Platform</a><br ...

Issue with displaying the file-field in Django admin after upgrading from Django 2.1 to version 3

Since upgrading from Django 2.1 to 3, the file field in Django admin is now displaying as "loading". https://i.sstatic.net/8JDWu.png An error is appearing in the console. https://i.sstatic.net/RCgwt.png https://i.sstatic.net/78YtG.png Previously, ther ...

What is the best way to create subpages within a survey?

If I want to create a survey page on the web with multiple questions, but I am facing a challenge. I do not want to have several different pages and use a "Next Button" that links to another page. I am struggling to come up with ideas on how to implement ...

Enhance the reusability of this function using Jquery

I have a group of checkboxes with classes like [.myCheckBox1, .myCheckBox2, ...] And another group with classes like [.myCheckBoxList1, .myCheckBoxList2, ...] How can I create reusable code to avoid duplication? Here is what I am aiming for: [FUNCTIO ...

Displaying Image from Jquery Ajax Response

I have a PHP script that can resize images with specified dimensions by passing the width and height as variables like so: resize.php?width=100&height=200. The content-type of this PHP script is set to image/jpg. Additionally, I have an HTML page wher ...

Receiving a JSON object in response after sending data to a server using JavaScript

I am facing an issue with passing an email and password on login click to a database using PHP. After testing the email and password combination, PHP sends back a JSON object. While I have verified that the PHP code is functioning correctly and returns a J ...

What is the best method for transferring data from an Excel spreadsheet into an HTML table?

I need assistance with integrating a dynamic Excel file into my website for football statistics. I want to be able to update the numbers in the spreadsheet and have the website's table automatically reflect these changes. Is there a solution availabl ...

Navigation for GitHub pages

I've been working on this for what feels like forever. The persistent Error 404 I'm encountering is with the /Quest/questlist.txt file. https://i.sstatic.net/NYYRa.png Here's the code snippet I've been using: ``// QuestCarousel.tsx ...

JQuery anonymous function fails to execute

Just starting to explore JQuery. I'm having an issue where the alert for '2' triggers, but never the alert for '1'. No matter how I rearrange the code, I always end up with the same outcome. JQuery is definitely loaded because at ...

What is the best way to sort an array of objects based on their properties?

I am working with an array of objects: let response = [{"id": 1, "name": "Alise", "price": 400, "category": 4}]; In addition to the array of objects, I have some arrays that will be used for filtering: let names = ["Jessy", "Megan"]; let prices = [300, ...

Issue with displaying parsed data using JSON and jQuery

I am experiencing an issue with a function I have written $.post('php/client.login.php', {username:username, password:password}, function(json){ var ids = json; alert(json.id); }, 'json'); The ...

Variations in the module pattern in JavaScript

Can someone help me understand the differences in these methods of creating a javascript "module"? I'm just looking for some clarification. A) var foo = function() { var bar = function() { console.log('test'); }; retur ...

What steps do I need to take in order to generate a legitimate link annotation within Adobe Acrobat by utilizing Acrobat

Seeking guidance on how to embed an Acrobat Javascript within Adobe Acrobat in order to generate a link annotation. The current method involves using the "addLink" function within the document object, which triggers a Javascript action upon clicking the li ...

Adjusting the transparency of the background without impacting the text itself

I've been struggling to create a loading screen with no luck. The animation itself looks fine, but the background is causing issues. Every time I try to adjust the opacity, it affects the text as well. @import url('https://fonts.g ...

Unable to convert JavaScript object to C# through deserialization

In order to pass a model from the controller action to the view, I included a list of objects and converted it into a JavaScript object to facilitate displaying markers on Google Maps. My goal is to send the selected object (selected marker) back to the co ...

How can we increase the accuracy of numerical values in PHP?

When performing a math operation in JavaScript, the result is: 1913397 / 13.054 = 146575.53240386088 However, when the same operation is performed in PHP, the result is slightly different: 1913397 / 13.054 = 146575.53240386 This discrepancy may be due ...

What is the method to combine multiple style values in vue.js?

Is there a way to create a div with a box shadow where the values can be changed using a slider? I am having trouble using more than one value stored in a data variable. Any suggestions on how to achieve this? <div :style="{ borderRadius: x_axis y_ ...

UV mapping with Plane BufferGeometry in Three.js

I'm facing some challenges creating a buffergeometry plane, specifically with the uv coordinates. Despite following advice from Correct UV mapping Three.js, I can't seem to achieve the desired result. Below is the snippet of code for the uv coor ...