I need help making sure these text boxes are correctly aligned and perfectly straight. Can you assist me with that?

I'm a bit out of practice with HTML and CSS, so forgive me for what may seem like a silly question. I want the text boxes on each side to be aligned perfectly, rather than slightly staggered as they are now. I know that my code has some issues both in HTML and CSS, but I'm not sure exactly what needs to be modified. Also, I realize that all the boxes, except the last one, have the class leftBoxes even though not all of them are positioned on the left side, which is confusing.

Here's the link to the jsfiddle. PLEASE NOTE that the small preview on jsfiddle doesn't display correctly when viewed in full screen mode. You can see an accurate representation of how it should look in full screen here.

Below is the snippet of my code:

HTML:

<body>

 
 <form>
        <label for="son">Sales Order Number:</label>
        <input type="text" class="leftBoxes" id="son" name="son">

        <label for="shipname">Ship to Name:</label>
        <input type="text" class="leftBoxes" id="shipname" name="shipname">

        <br>

        <label for="arnum">AR Division Number:</label>
        <input type="text" class="leftBoxes" id="arnum" name="arnum">

        <label for="shipadd1">Ship to Address 1:</label>
        <input type="text" class="leftBoxes" id="shipadd1" name="shipadd2">

        <br>

        <label for="cnum">Customer Number:</label>
        <input type="text" class="leftBoxes" id="cnum" name="cnum">

        <label for="shipadd2">Ship to Address 2:</label>
        <input type="text" class="leftBoxes" id="shipadd2" name="shipadd2">

        <br>

        <label for="custponum">Customer PO Number:</label>
        <input type="text" class="leftBoxes" id="custponum" name="custponum">

        <label for="city">Ship to City:</label>
        <input type="text" class="leftBoxes" id="city" name="city">

        <br>

        <label for="orderdate">Order Date:</label>
        <input type="text" class="leftBoxes" id="orderdate" name="orderdate">

        <label for="state">Ship to State:</label>
        <input type="text" class="leftBoxes" id="state" name="state">

        <br>

        <label for="zip">Ship to Zip Code:</label>
        <input type="text" class="rightBoxes" id="zip" name="zip">


      </form>
      
  </body>

CSS:

body {
  background-color: lightblue;
  text-align: center;
}

.leftBoxes {
  display: inline-block;
  margin-right: 100px;
}
.rightBoxes {
  display: inline-block;
  margin-left: 100px;
}

Answer №1

Utilizing a grid layout could be beneficial for your design. Take a look at the example I've provided below:

form {
  display: grid;
  grid-template-columns: auto auto auto auto;
}


body {
  background-color: lightblue;
}

input {
  display: inline-block;
  margin-right: 10px;
}
 <body>

 
 <form>
        <label for="son">Sales Order Number:</label>
        <input type="text" class="leftBoxes" id="son" name="son">

        <label for="shipname">Ship to Name:</label>
        <input type="text" class="leftBoxes" id="shipname" name="shipname">



        <label for="arnum">AR Division Number:</label>
        <input type="text" class="leftBoxes" id="arnum" name="arnum">

        <label for="shipadd1">Ship to Address 1:</label>
        <input type="text" class="leftBoxes" id="shipadd1" name="shipadd2">

       

        <label for="cnum">Customer Number:</label>
        <input type="text" class="leftBoxes" id="cnum" name="cnum">

        <label for="shipadd2">Ship to Address 2:</label>
        <input type="text" class="leftBoxes" id="shipadd2" name="shipadd2">

       

        <label for="custponum">Customer PO Number:</label>
        <input type="text" class="leftBoxes" id="custponum" name="custponum">

        <label for="custponum">Ship to City:</label>
        <input type="text" class="leftBoxes" id="custponum" name="custponum">

        

        <label for="orderdate">Order Date:</label>
        <input type="text" class="leftBoxes" id="orderdate" name="orderdate">

        <label for="shipstate">Ship to State:</label>
        <input type="text" class="leftBoxes" id="shipstate" name="shipstate">

        

        <label  for="shipzip">Ship to Zip Code:</label>
        <input type="text" class="rightBoxes" id="shipzip" name="shipzip">
      </form>
      
  </body>

Answer №2

In order to achieve the desired layout, consider utilizing either flexbox or grid. You may want to implement:

form{
  display:flex;
  flex-direction: column;
}

Answer №3

Definitely not the Answer However, if we include

[type='text']{  
margin-top:10px; 
}

It can enhance the appearance a bit.

There is a probable reason why the final one is acting strangely. The content in the text field has adopted the text-align center style, causing it to be positioned exactly in the middle.

It would be intriguing to find out if there is a resolution for correcting the behavior of the last element!!!

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

Exploring the functionality of URLs in Node.js

I am working on testing an array of URLs to ensure that each one returns a 200 response code. So far, I have written the following code to accomplish this task. However, I have encountered an issue where only the last URL in the array is being tested. How ...

Executing a Data Factory Pipeline using JavaScript

In Azure Data Factory, I constructed a pipeline to transfer data from an Azure Storage Table to an Azure SQL database Table. The Azure Storage Table receives data from a JavaScript chatbot that captures responses and saves them in the table. I want to ini ...

Should one refrain from specifying a Content Type for a webpage?

I come from Brazil and currently reside here. In the Portuguese language, there are many words with accented letters. If the correct charset is not applied, these accented letters may appear as garbage when rendered on a browser. In my daily work, I often ...

Is there a way to verify the location of an element?

Currently, I am attempting to monitor the position of the 'car'. When the car reaches a top offset of 200px, I would like to apply a specific property to the 'phone' element. The concept is that as you scroll down, the car will move, an ...

Error in Bootstrap table implementation leading to truncation of tbody height due to data-detail-view property

I'm currently working on integrating Bootstrap-Table's detailView feature into my project. However, when I enable data-detail-view="true" for my table, the height of the table element shrinks to 0. Strangely, clicking on any column with ...

Is it possible for setTimeout to not increment the counter in node.js?

Even though the loop is executed multiple times in the Node.js program below, why does the control not exit the loop? I made sure to increment the value of i within setTimeout instead of forgetting to do i++ in the for loop. function abc () { for(var ...

using angular.js to assign a value to an <input> field

There seems to be an issue with the code, as I am unable to see the value in the HTML: '<div ng-app="BusinessinfoModule" ng-controller="BusinessinfoController" <label>Your Business Name</label> <input ...

Is it possible to use pushState during an Ajax request?

A challenge I am facing is how to enable my client to return to a 'previous page' using the browser back button. The issue arises because these 'pages' are fetched via Ajax and displayed in a modal window. After doing some research, it ...

Refresh Div/PartialView periodically

I have a function that performs an Ajax call, retrieves a result, and functions perfectly. @foreach (var fighter in Model.Fighters) { @Ajax.ActionLink(fighter.FirstName + " " + fighter.LastName, "ShowResults",new {id = fighter.FighterID }, new AjaxOptions ...

The chosen option in the q-select is extending beyond the boundaries of the input field

Here's the code snippet I used for the q-select element: <q-select square outlined fill-input standout="bg-grey-3 text-white" v-model="unit_selection" :options="units&qu ...

Is there a way I can retrieve all elements excluding the final one using jQuery?

I need assistance with removing specific div elements. <div class="myClass"></div> <div class="myClass"></div> <div class="myClass"></div> <div class="myClass"></div> These divs are created dynamically, and ...

Display the JSON data in an organized HTML table

I am struggling to display a JSON response in an HTML formatted table. It is showing as unidentified. Here is the JSON response I am working with: { "status": "200", "success": true, "mesg": "Data Found", "refNo": "10101010", "benefici ...

The command express is not recognized in the current shell

Encountering a strange error while attempting to install the express-generator with and without using sudo. The necessary commands are: npm install express-generator -g followed by express --ejs name_here. However, upon executing the first command, the fo ...

JavaScript can intelligently extract and categorize an array of objects based on their properties

In essence, I aim to develop a versatile function "organize" that can transform the following data structure: [ { name: 'band1', type: 'concert', subtype: 'rock' }, { name: 'band2', type: 'concert' ...

Organizing Checkbox Groups for Validation in Bootstrap

My form consists of 2 checkboxes and I only want to submit the form if at least one checkbox is checked. The current code requires both checkboxes to be checked, but I tried grouping them using the name attribute without success. How can I group checkbox ...

Is the entire web page generated on the server with each request using getServerSideProps()?

As I understand it, getServerSideProps will dynamically generate the complete page on every request, rather than pre-building it. But does getServerSideProps always generate the entire page upon each server request, or only when the data in the database ha ...

Delete the query parameters from the URL with the help of jQuery and update the browsing history with

Is there a way to remove a specific parameter from the URL without refreshing using push state? I am familiar with how to add something to the URL: var url = $(location).attr('href'); history.pushState(null, null, url + '&view=new_d ...

What is the best way to adjust the equal right padding or margin in the header for both IOS and Android using React Navigation options?

To ensure an equal gap on both sides for both IOS and Android platforms, I utilized a combination of techniques. For the right side, I achieved this using a minus margin, positive padding, and Platform. <Stack.Navigator screenOptions={{ contentSty ...

d3 split bar chart with a horizontal layout

https://i.sstatic.net/P6qck.png I am interested in creating a split difference bar chart using d3 similar to the image provided. I have two input arrays - one for y-axis labels and one for data as shown below: data = [[35,90], [60,45], [80,90], [95,90]] m ...

Fluctuating and locked header problem occurring in material table (using react window + react window infinite loader)

After implementing an Infinite scrolling table using react-window and material UI, I have encountered some issues that need to be addressed: The header does not stick to the top despite having the appropriate styles applied (stickyHeader prop). The header ...