Labels arranged in a fixed width format

Is there a way to ensure that the labels for the inputs are all the same width, creating a more cohesive table-like layout?

Imagine it as two columns: one for the labels and one for the inputs.

Here is the code I have so far:

th, td, table{border: 2px solid black;
border-collapse: collapse;
}

th, td{width: 100px}

table{width: 100%;
text-align: center;}

body{font-family: "Bradley's Hand", cursive;}

.label{display: inline-block;
width: 100px}

input{width: 200px;}
<body>
<h1>Add Transactions</h1>

<fieldset>
<legend>Use This Form To Add Transactions</legend>

<form action="add.php" method="post">
<label class="label" for="date">Transaction Date: </label>

<input type="date" name="date" required>
<br>
<br>
<label class="label" for="amount">Transaction Amount: </label>
<input type="number" name="amount" required>
<br>
<br>
<label class="label" for="merchant">Merchant: </label>
<select name="merchant" required>
<option value="" disable selected>Select One</option>
<option value="other">Other</option>
</select>
<br>
<br>
<label class="label" for="om">Other Merchant: </label>
<input type="text" name="om">
<br><br>
<label for="type" class="label">Transaction Type: </label>
<select name="type" required>
<option value="" disable selected>Select One</option>
<option value="other">Other</option>
</select>
<br>
<br>
<label for="ot" class="label">Other Transaction Type: </label>
<input type="text" name="ot">
<br><br>
<label for="source" class="label">Source: </label>
<select name="source" required>
<option value="" disable selected>Select One</option>
<option value="other">Other</option>
</select>
<br>
<br>
<label for="os" class="label">Other Source: </label>
<input type="text" name="os">
<br>
<br>
<input type="reset">
<input type="submit" value="Save Transaction">
</form>
</fieldset>
</body>
</htm>

Thank you for any help!

P.S. I can provide more clarification if needed!

P.P.S. And when I say

like a table

I'm referring to the layout structure, not necessarily using an actual <table> element.

Answer №1

To easily tackle this issue, utilize CSS-Grid. This will ensure full responsiveness and create a table-like layout. To keep the buttons at the bottom in their original position, enclose them within an additional div.

body {
  font-family: "Bradley's Hand", cursive;
}

form {
  display: grid;
  grid-template-columns: min-content auto;
  grid-row-gap: 2em;
  white-space: nowrap;
}

.last-row {
  grid-column: span 2;
}

.last-row input {
  width: 200px;
}
<body>
  <h1>Add Transactions</h1>
  <fieldset>
    <legend>Use This Form To Add Transactions</legend>

    <form action="add.php" method="post">
      <label class="label" for="date">
        Transaction Date:
      </label>
      <input type="date" name="date" required>

      <label class="label" for="amount">
        Transaction Amount:
      </label>
      <input type="number" name="amount" required>

      <label class="label" for="merchant">
        Merchant:
      </label>
      <select name="merchant" required>
        <option value="" disable selected>
          Select One
        </option>
        <option value="other">
          Other
        </option>
      </select>
      
      <label class="label" for="om">
        Other Merchant:
      </label>
      <input type="text" name="om">

      <label for="type" class="label">
        Transaction Type:
      </label>
      <select name="type" required>
        <option value="" disable selected>
          Select One
        </option>
        <option value="other">
          Other
        </option>
      </select>

      <label for="ot" class="label">
        Other Transaction Type:
      </label>
      <input type="text" name="ot">

      <label for="source" class="label">Source: </label>
      <select name="source" required>
        <option value="" disable selected>
          Select One
        </option>
        <option value="other">
          Other
        </option>
      </select>

      <label for="os" class="label">Other Source: </label>
      <input type="text" name="os">
      <div class="last-row">
        <input type="reset">
        <input type="submit" value="Save Transaction">
      </div>
    </form>
  </fieldset>
</body>
</htm>

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

Unchecking and checking the radio button is necessary in order for it to function properly

Today, I'm puzzled by the odd behavior of my radio buttons in a pixel drawer project. In order for the radio button to function properly, I have to uncheck it and then recheck it. The pixel drawer allows me to change colors and sizes using these radio ...

What causes the image to vanish once the CSS animation is activated?

Is there a reason why the image disappears after the animation completes? :/ .coin { width: 200px; height: 200px; background-size: cover; animation: CoinflipRoll 6s steps(199); animation-delay: .5s; animation-fill-mode: forwards; ...

Design: Seeking a layout feature where one cell in a row can be larger than the other cells

To better illustrate my goal, refer to this image: Desired Output <\b> Currently, I'm achieving this: current output Imagine 7 rows of data with two columns each. The issue arises in row 1, column 2 where the control needs to span 5 row ...

Struggling to integrate the navigation bar with Wordpress platform

For a while now, I have been facing challenges with the navigation bar on the WordPress theme I am currently creating. I am struggling to get the navigation bar to display correctly. Below is the code snippet from my header.php file: <body> &l ...

Django causing CSS issues following the utilization of an if statement

I have been working on adding a dropdown list to my navbar, which I created using Bootstrap. However, whenever I place the dropdown menu inside an if statement for looping categories into a list, it seems to be breaking the CSS. Check out the navbar witho ...

Utilizing Fullcalendar v5's sticky header feature alongside a Bootstrap fixed top navigation bar for a seamless

Currently experimenting with the latest version of fullcalendar 5.4.0. I have integrated the calendar into a bootstrap 4 web page that features a fixed navigation bar at the top. The issue arises when attempting to set stickyHeaderDates, aiming to keep th ...

Joomla CSS styling malfunctioning

I've been exploring the creation of an in line menu using Joomla 1.6 and CSS. The issue arises when Joomla removes <span class="dmenu"> from the document before saving, despite having all cleanup options turned off. This led me to try a couple ...

Troubleshooting a layoutUnit problem with Primefaces southern region

I'm encountering an issue with my PrimeFaces layout. The south layoutUnit is not displaying on the page, and I am unsure why. Below is the code for the page: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/ ...

Using AJAX to store values from PHP SESSION into form inputs with POST data

Wondering how to store ajax-sent data from form inputs as session variables? I have already included session_start() in header.php. Saving the code in the database is working fine. Here's what I attempted: HTML form <form action='' meth ...

Issues with CSS animation functionality have been detected in the Edge browser

In this particular div, I have two spans enclosed. I've created a loader which features a circle filling up with red color repeatedly. While everything appears to be functioning smoothly in Google Chrome, there's a noticeable glitch when it comes ...

Issue with animating multi-column layout in Chrome causing display problems

I'm currently utilizing jQuery to create an animated multi-column layout that extends off the screen horizontally. I have implemented two controllers - one red and one blue - to navigate back and forth within the layout. Strangely enough, while the an ...

What is the best way to place a header in a specific location on a

As I continue working on my project, I am facing a challenge in positioning the headings in specific places. My ultimate goal is to achieve a look similar to Figure 1 for my headings. [Figure 1][1] However, as of now, my layout resembles Figure 2. I find ...

What is the process for obtaining an HTML form, running it through a Python script, and then showcasing it on the screen

I am inquiring about the functionality of html and py script. .... The user enters 3 values for trapezoidal data from the html form: height, length of side 1, and length of side 2, then clicks submit. The entered values are then sent to be calculated using ...

Number input field failing to update value upon pressing 'enter'

App features an input element that updates when the user presses enter, clicks away, or clicks the next button. Upon inspecting the element in the developer tools, it was observed that the value attribute updates when the user clicks away or clicks the nex ...

Unable to make changes to the text within the textarea field

Currently, I am in the process of creating a script to streamline the tedious task of providing teaching feedback. To scrape data such as student names and classes, I am utilizing selenium/python. While everything is running smoothly, I have encountered an ...

I attempted to update the text on an HTML page using the content of "conetnt", however, it was unsuccessful

.custom-div { outline: none !important; width: 450px; margin: auto; background-color: #ccc !important; text-indent: -9999px;} .custom-div::before{content: 'sample';color: black;} ...

What is the reason CURL is unable to retrieve the HTML content of a page?

Check out the code snippet below: <?php $url = "https://www.facebook.com/login/identify?ctx=recover&lwv=110"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); curl_setopt($ch, C ...

Open the URL in a new tab based on certain conditions

Currently, my page redirects if a specific checkbox is selected and the "submit" button is clicked: if request.Form("myCheckbox") = "on" then response.Redirect("/newPage.asp?txt="staff"") else response.Redirect("/thisPage.asp") end if I ...

Display the toggle button for expanding/collapsing text only when the length of the string exceeds 50 characters

Is there a way to only show a "read more/less" button in a table if the content exceeds 50 characters? The table contains a mix of content, some short announcements with about 10 characters and others with over 100. <div class="col"> <span ng-c ...

What is the best way to increase the spacing between inline-block elements?

Just to clarify, I am not looking to delete space between inline-block elements - rather, I want to insert it. My goal is to create a grid of menu items that can accommodate 2, 3, or 4 items per row, and I hope to achieve this using media queries. Is the ...