Steps for displaying input forms in rows one by one

I am currently struggling to format a form properly. In the form I'm working on, I want the first name and last name to be displayed in one row, followed by email and phone number in the same row but different column, and below that, password and confirm password fields. Despite trying various solutions, I can't seem to achieve the desired layout as shown in this image: example

Please review my code snippet and assist me with this issue:

code and help me with this case

Answer №1

To organize the labels and input fields, I would split them into three separate rows within divs. Each label and input field pair would be wrapped in its own div for better alignment. One way to position them effectively is by utilizing flexbox properties. For instance, setting the container div.row as a flex container with a fixed width (such as max-width: 50%) and justify-content: space-between can push the columns to either end of the container for a clean layout.

.row {
  display: flex;
  justify-content: space-between;
  max-width: 50%;
}
<div class="form">
          <h2>Let's do this!</h2>
          <form action="#" method="get">
         <div class="row"> <div><div class="input">
            <label for="firstName"> First Name </label>
          </div>
          <input type="firstName" id="firstName" name="firstName" />
</div><div>
          <div class="input">
            <label for="lastName">Last Name</label>
          </div>
          <input type="lastName" id="lastName" name="lastName">
            </div></div>
          <div class="row"><div><div class="input">
            <label for="email">Email</label>
          </div>
          <input type="email" id="email" name="email">
</div><div>
          <div class="input">
            <label for="lastName">Phone Number</label>
          </div>
          <input type="phoneNumber" id="phoneNumber" name="phoneNumber">  
</div></div><div class="row"><div>
          <div class="input">
            <label for="password">Password</label>
          </div>
          <input type="password" id="password" name="password">
            </div><div>
          <div class="input">
            <label for="confirmPassword">Confirm Password</label>
          </div>
          <input type="confirmPassword" id="confirmPassword" name="confirmPassword">

        </div></div>
      </form>

Answer №2

If you want to display inputs row by row, follow this structure:

Enclose each label and its corresponding input within a div. Place two of these div wrappers inside another div with the class "row".

    <div class="row">
      <div>
        <label for="firstName"> First Name </label>
        <input type="firstName" id="firstName" name="first Name" />
      </div>

      <div>
        <label for="lastName"> Last Name </label>
        <input type="lastName" id="lastName" name="last Name">
      </div>
    </div>

To learn more about flexbox and how to use it, visit this link.

Add the following CSS for the "row" class:

.row {
  display: flex;
  /* ensures children elements are in one row */
  flex-wrap: wrap;
  /* allows children to move to the next line if space is insufficient */
  gap: 10px;
  /* creates spacing between children */
  padding-top: 10px;
  /* adds space above the row */
}

h2 {
  margin-bottom: 0px
}

label {
  display: block;
}
<div class="form">
  <h2>Let's do this!</h2>
  <form action="#" method="get">

    <div class="row">
      <div>
        <label for="firstName"> First Name </label>
        <input type="text" id="firstName" name="first Name" />
      </div>

      <div>
        <label for="lastName"> Last Name </label>
        <input type="text" id="lastName" name="last Name">
      </div>
    </div>

    <div class="row">
      <div>
        <label for="email"> Email </label>
        <input type="email" id="email" name="Email">
      </div>

      <div>
        <label for="phoneNumber"> Phone Number </label>
        <input type="tel" id="phoneNumber" name="phone Number">>;
      </div>
    </div>

    <div class="row">
      <div>
        <label for="password"> Password </label>
        <input type="password" id="password" name="Password">>;
      </div>

      <div>
        <label for="confirmPassword"> Confirm Password </label>
        <input type="password" id="confirmPassword" name="Confirm Password">>;
      </div>
    </div>
  </form>

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 the table not displaying properly in the print preview with a messy

I have a large table with multiple rows. Due to its length, I have provided a link to the jsfiddle where you can view it: jsfiddle. The table is structured in HTML and contains many rows with various attributes. <table> <thead>text here!</t ...

Button with embedded Bootstrap dropdown

I need help with centering a dropdown menu on my webpage. I followed the instructions, but it's still appearing next to the button instead of in the center. Below is the code snippet: <div class="btn-group"> <button type=" ...

Is there a way to change HTML retrieved from an AJAX request before inserting it into the document?

I am utilizing an ajax call to retrieve an HTML page from the server; the ajax call is structured as follows: function loadHtml() { $.ajax({ type : 'GET', async : false, url : &apos ...

seamless blending effect as the opacity transitions smoothly on an element with a applied filter

I've been working with a DIV that has a blur filter applied to it, and I'm attempting to smoothly "fade in" the DIV using CSS opacity (going from 0 to 1) with a one-second transition. However, even though the DIV does fade in, it's quite gli ...

Ways to duplicate a letter in HTML?

How can a character be printed repeatedly within a table cell using only HTML or HTML and CSS (excluding HTML5)? *(limiting to only HTML or a combination of HTML and CSS) ** The goal is to print the character "." across the entire length of the cell, wit ...

Trouble with closing Bootstrap 4 modal

My Bootstrap 4 modal is causing issues as it pops up on button click but won't close unless I refresh the page. I've been attempting to get it to close by clicking the 'close' button or simply by clicking anywhere on the main page body. ...

Navigating users through websites using AJAX techniques

My one-page web application follows a specific flow of execution: Main -> AJAX Content -> Main The user starts on the main screen, enters input data, and presses a button to initiate the AJAX content, which consists of several sequential steps. Upo ...

Overflow of text arranged horizontally within a span element situated inside a div container

I am currently working on developing a ticketing system that involves using nested div elements to organize content. Each ticket is represented by a main div containing various other nested divs and media such as images. While the functionality of the sys ...

The Datalist feature in the MVC application is malfunctioning on the production server, yet it is functioning properly

In my application, I am facing an issue with the datalist functionality. It works perfectly in the Development environment but fails to show any lookup results in the Production environment. Using datalists is crucial for providing auto-complete features, ...

HTML5 CSS and Rails theme

I am currently utilizing a free HTML5 template found at this URL: Despite my efforts, I am unable to successfully implement the background images from the main.js file (bg01.jpg, bg02.jpg, bg03.jpg). How should I correctly reference these image files wit ...

Moving items in a leftward direction

I am trying to create a CSS animation that makes multiple objects slide from right to left. The height of these objects should be random and the speed of the animation should also vary randomly. While I have successfully achieved this using JavaScript, I a ...

Maximize the YouTube video for full screen viewing

Take a look at the code snippet from our page here: <div className={styles.videoPreview}> <iframe src={`${videoData[router.locale]}?autoplay=0`} title="Flytime" ...

Modifications made to the content of the element can disrupt the functioning of the delegated event handlers tied to its parent

Currently, I am working on implementing a drop-down menu for a school project. While most of the functionality is in place, I encountered an issue with JQuery events that has me stumped. When I click on a list item, the name is set correctly, but then the ...

Make sure to always retrieve the previous state in your React application

After researching and experimenting based on my previous inquiry, I have devised a solution to properly store the state: if (value === 'checkpoint') { if (checked1) { this.setState({checked1 : false}) localStorage.setObject('che ...

Python Issue with BeautifulSoup: find_all() returning incorrect list of elements

I am currently using Python 2.7.3 and the bs.version I have is 4.4.1 However, when running this code snippet: from bs4 import BeautifulSoup # parsing html = """ <html> <head id="Head1"><title>Title</title></head> <body&g ...

Having trouble with the display of styles on Material UI Cards?

I am currently attempting to customize the default Material UI classes by using useStyles and applying a classname of titleSection. My goal is to make the titleSection bold and in Roboto font, but unfortunately, those styles are not being applied. Below i ...

Steps for compiling SCSS to CSS using Angular-CLI and moving it to the assets directory

I am currently working on an Angular 5 project with an assets folder where I store my common CSS file and reference it in index.html. I now plan to create a new folder called "sasstyles" and place some .scss files there. When I compile or run the project ...

Transforming HTML div elements into a PHP array

I am trying to work with HTML code that consists of multiple div elements, each containing a different source. <div class="moviefilm"> SURSA 1 </div> <div class="moviefilm"> SURSA 2 </div> <div class="moviefilm"> SURSA 3 &l ...

How to reset an HTML5 form using the submit button

Can you prevent a form from resetting when you click the submit button? As it stands, clicking the submit button in HTML5 clears all the form fields. Is there any way to retain the previous values instead of resetting them? ...

Endless Loop Seamless Vertical JavaScript Experience

I've been working with an HTML table structure of data and was successful in setting up a vertical list loop using some JavaScript. However, I'm facing challenges in achieving a smooth constant vertical scroll. Currently, it goes row by row when ...