Tips for correctly aligning input text boxes

https://i.sstatic.net/9fVwA.jpg

I have created a code for an average calculator using HTML, CSS, Bootstrap, and JavaScript.

The problem I am facing is with the alignment of the input text boxes. How can I adjust them properly?

The user should enter the quantity and price of the first four purchases. When they click on calculate, they should receive the average buying price of all quantities combined.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="CSS/bootstrap.min.css">
    <style type="text/css">
    </style>
    <script type="text/javascript">
        function doadd() 
    {
        var no1= document.getElementById('txtno1');
        var no2= document.getElementById('txtno2');
        var no3= document.getElementById('txtno3');
        var no4= document.getElementById('txtno4');
        var no5= document.getElementById('txtno5');
        var no6= document.getElementById('txtno6');
        var no7= document.getElementById('txtno7');
        var no8= document.getElementById('txtno8');
        var result=document.getElementById('txtresult');
        var A =Number(no1.value)*Number(no2.value);
        var B =Number(no3.value)*Number(no4.value);
        var C =Number(no5.value)*Number(no6.value);
        var D =Number(no7.value)*Number(no8.value);
        var F =Number(no1.value)+Number(no3.value)+Number(no5.value)+Number(no7.value);
        var E = A+B+C+D;
        result.value = E/F;
        }
    </script>
    <title>Average Calculator</title>
    </head>
    <body>
    <div class="container bg-success text-white">
    <div class="row">
    <div class="col-4">
    <span class="badge bg-dark"></span>
    </div>
    <div class="col-4 text-center fw-bold">
    Average Calculator
    </div>
    <div class="col-2">
    </div>
    </div>
    </div>
    <div class="container fst-italic">
    <br>
    <br>
    <p>You can use this tool to calculate the average price of stocks you bought at different prices and quantities.
    </p>
    <br>
    <p>Enter 1st Purchase quantity: <input type="text" id='txtno1' ><p/>
    <p>Enter 1st Purchase price   : <input type="text" id='txtno2'></p>
    <p>Enter 2nd Purchase quantity: <input type="text" id='txtno3'></p>
    <p>Enter 2nd Purchase price   : <input type="text" id='txtno4'></p>
    <p>Enter 3rd Purchase quantity: <input type="text" id='txtno5'></p>
    <p>Enter 3rd Purchase price   : <input type="text" id='txtno6'></p>
    <p>Enter 4th Purchase quantity: <input type="text" id='txtno7'></p>
    <p>Enter 4th Purchase price   : <input type="text" id='txtno8'></p>
    <input type="button" id="btnsum" value="Calculte"
    onclick="doadd();">
    <p>Average Buying Price <input type="text" id="txtresult"/></p>
    </div>
    </body>
    </html>

Heading
=======

Answer №1

If you have tabular data, presenting it in a table format would be the most appropriate choice. This will not only reduce the amount of text but also make the information more readable:

<table>
  <tr>
    <th></th>
    <th>quantity</th>
    <th>price</th>
  </tr>
  <tr>
    <td>1st Purchase</td>
    <td><input type="number" step="1"></td>
    <td><input type="number" step="0.01"></td>
  </tr>
  <tr>
    <td>2nd Purchase</td>
    <td><input type="number" step="1"></td>
    <td><input type="number" step="0.01"></td>
  </tr>
  <tr>
    <td>3rd Purchase</td>
    <td><input type="number" step="1"></td>
    <td><input type="number" step="0.01"></td>
  </tr>
  <tr>
    <td>4th Purchase</td>
    <td><input type="number" step="1"></td>
    <td><input type="number" step="0.01"></td>
  </tr>
</table>

Answer №2

To streamline your form layout, assign each label and input field to their own row. For instance:

  <div class="row">
    <div class="col-md-6">
     Please provide quantity for 1st purchase:
    </div>
    <div class="col-md-6">
     <input type="text" id='txtno1' >
    </div>
   </div>

Repeat this pattern for all label and input field combinations.

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

Unable to insert flag image into the <option> tag

Struggling to add a flag image to the options using any method (html,css)! <select> <option value="rus" selected>Rus</option> <option value="Uzb" >Uzb</option> <option value="eng">Eng</option> </s ...

Avoid triggering a keydown event if certain div elements have been clicked

When the user presses the space bar, my script is set up to perform certain actions, such as stopping an audio player: $('html').keydown(function(e){ if(e.keyCode == 32){ // Stop the audio player } } However, an issue arises when a ...

Concealing the WordPress sidebar specifically for mobile phones, excluding iPads, tablets, and other devices

I currently have Google AdSense displayed in the sidebar of my website, but it appears distorted when viewed on a mobile phone. My objective is to eliminate the sidebar when the site is accessed via a mobile device, while maintaining it for all other devic ...

Get rid of the blue dots that appear on anchor tags

I am facing a strange issue with the anchors on my webpage. There are a few anchor tags in my body: <a href="link1.html"></a> <a href="link2.html"></a> <a href="link3.html"><img src="img1.png" /></a> Interestingl ...

Tips for arranging letters on separate lines using CSS

I have a set of four divs that display numbers, and I want to show the corresponding words below each number. Despite trying to use the p tag with white-space: pre; in CSS, I have not been successful: #c { padding-top: 30px; padding-bottom: 30px; } ...

I'm experiencing an issue where the anchor links in my Node/Express application are not properly redirecting

As I embark on my first node.js/express.js project, I am faced with a unique challenge when it comes to my directory structure. Within the index.html and favorites.html files, I have carefully included anchor tags to facilitate smooth navigation between t ...

The removeEventListener method in JavaScript fails to function properly

On my website, I have a unique feature where clicking an image will display it in a lightbox. Upon the second click, the mouse movement is tracked to move the image accordingly. This functionality is working as intended, but now I'm faced with the cha ...

Use jQuery to move list items up or down when clicking on an element outside the list, as long as they contain checked checkboxes

I am in need of creating a user interface that includes both a "Move Up" button and a "Move Down" button. These buttons will allow users to reposition list items by moving them up or down within the list, based on whether they click the "Move Up" or "Move ...

Creating a looping animation on multiple elements using jQuery that makes them fade in and out at different intervals

I am currently working on creating a fade in and out animation for multiple elements using jquery. It's a bit complex to explain, so I will start by sharing the relevant code. $(document).ready(function() { $("#1").delay(0).animate({ ...

The HTML div is not aligned in the center even when using flexbox

After creating a list within a centered flex div, it seems that the list is not aligning properly. I used flex on the list-div2 and the translate rule in the parent's middle-text div, but it still doesn't look centered as expected. Can anyone p ...

How can I transfer a particular data value from a div to JavaScript within Laravel 5.0?

Displaying separate square divs based on integers retrieved from the database. This is the front-end view. I want to pass the room ID (code) to a JavaScript function when clicking on these div elements. https://i.stack.imgur.com/aIYTr.png Below is my cur ...

Would it be beneficial to create classes for frequently used CSS styles and apply them to HTML elements?

Check out my code snippet: style.css .bg-cover{background-size:cover; background-position:center;} .opacity-1{opacity:0.1;} .border-3-solid{border-width:3px; border-color: solid;} .black-border{border-color:#000;} .full-width{width:100%;} index.html ...

Accessing the name attribute of option tags in a controller: A guide

Within my blade file, the following code snippet is present: <select class="form-control" name="region_id_report"><option name="blank">No Region</option></select> Inside my controller, a variable named $regionidreport stores the v ...

transferring background-image in html between elements

Imagine having a three-level hierarchy HTML code structured like this: <section> <div id="outer"> <div id="inner"> </div> </div> </section> If we set background-image:someImage.jpg to the section, and backg ...

The background image is failing to adapt to mobile devices

It seems like I might be overlooking something simple, but I have 4 sections, each with a background image similar to this one and appearing one after the other: .bg { background-image: url("../images/bg1.jpg"); position: absolute; to ...

Display tab content by clicking on a link from an external source

How can I make a link, <a href="#" class="link-one">Link</a>, outside of nav-tabs activate a tab-panel/tab-content in Bootstrap 5? Can someone simplify this for me? // Show relevant Bootstrap tab based on an outside link cl ...

Presenting XML data in HTML using a customized CSS stylesheet

I've explored various methods for showcasing an XML file on a web page using HTML, but I haven't yet encountered one that incorporates a CSS style sheet. The XML file I have already includes a CSS style sheet. When viewed in a web browser, the . ...

Apply a CSS class to the selected radio button when retrieving row data from the table

How can I dynamically add a CSS class to a snippet of code when a radio button is selected? Here's the jQuery Snippet: $(document).ready(function (){ $("input:radio").click(function () { if ($(this).is(":checked")) { var empid ...

Ways to center items in a row-oriented collection

When dealing with a horizontal list, the issue arises when the first element is larger than the others. This can lead to a layout that looks like this. Is there a way to vertically align the other elements without changing their size? I am aware of manual ...

Incorporate the list seamlessly into the remaining content of the page

https://i.sstatic.net/lIsnd.png https://i.sstatic.net/Nftto.png I am currently developing a Vue component that utilizes an API call to search for a list of cities based on user input. My challenge is ensuring that the displayed list does not overlap with ...