Is there a way to position two forms next to each other in alignment?

I would like to display two forms side by side. Currently, I have one form shown here: http://gyazo.com/093efe95337ace40fe633adb88b76c2d. I want the same form to be displayed on the right-hand side as well.

.comments-section .comment-form {
  padding: 20px;
  background: #f8f8f8;
  border: 1px solid #dddddd;
  border-radius: 3px;
}
.row {
  margin-left: -15px;
  margin-right: -15px;
}
<div class="tab-pane active" id="company-contact">
  <div class="company-profile company-contact">
    <h3>Create an Account With Us</h3>

    <form class="comment-form">

      <div>

        <div class="left">
          Username:
        </div>
        <div class="right">
          <div class="row">
            <div class="col-xs-4">
              <input type="text" required>
            </div>
          </div>
        </div>
      </div>



      <div class="left">
        Email:
      </div>
      <div class="right">
        <div class="row">
          <div class="col-xs-4">
            <input type="email" required>
          </div>
        </div>
      </div>


      <div class="left">
        Password:
      </div>
      <div class="right">
        <div class="row">
          <div class="col-xs-4">
            <input type="password" required>
          </div>
        </div>
      </div>
  </div>
</div>

</form>

Can anyone guide me on how to achieve this layout?

Answer №1

Step one, make sure to close your form before the first two div elements.

Next, you can insert a second form right after closing the first one.

Assign a class to both of these forms.

In your CSS file, include the following code:

.sideBySideForm{
display: inline-block;
}

I hope this explanation is helpful and I apologize for any language errors :)

Answer №2

Maybe you should consider arranging your input boxes in this way:

<h3>Register for an Account</h3>

    <form class="comment-form">
        
        Username:<input class="comment-form"  type='text' name='username' id='username'  maxlength="50" placeholder="Username" />

        Email:<input class="comment-form"  type='text' name='email' id='email'  maxlength="50" placeholder="Email" />

        Password:<input class="comment-form"  type='password' name='password' id='password'  maxlength="50" placeholder="Password" />
    
    </form>

Answer №3

Initially, it is important to clarify the meaning of

I want the form on the right side to match the one on the left

Instead of diving into specifics, I encountered a similar issue where using two consecutive forms in HTML did not yield the desired outcome.

In your scenario, there are two potential solutions :

  1. If both forms have the same action (PHP action file) :

In this case, you can simply utilize a single form with duplicated input fields to achieve a layout like this:

<form action='youraction.php'>
    <div class='insameline'>
        <input> username </input>
        <input> username </input>
    </div>
    <div class='insameline'>
        <input> email </input>
        <input> email </input>
    </div>
    <div class='insameline'>
        <input> password </input>
        <input> password </input>
    </div>
</form>

You can then apply your preferred styles or include the following:

div.insameline {
    display: inline-block;
    margin-block-end: 0.83em;
}

Adjusting the value of margin-block-end can help shift the second block to the right as needed

  1. If you require the same form but with different actions, your code might resemble this:
<form action='youraction.php'>
    <div class='insameline'>
        <input> username </input>
        <input formaction='yourotheraction.php'> username </input>
    </div>
    <div class='insameline'>
        <input> email </input>
        <input formaction='yourotheraction.php'> email </input>
    </div>
    <div class='insameline'>
        <input> password </input>
        <input formaction='yourotheraction.php'> password </input>
    </div>
</form>

Answer №4

<div class="tab-pane active" id="company-contact">
  <div class="company-profile company-contact">
    <h3>Sign Up With Us</h3>

    <form class="comment-form">


<div class="row">
  <div class="col-md-4">
      <div class="left">
          Username:
      </div>
            <input type="text" required/>
 </div>
  <div class="col-md-4">
      <div class="left">
        Email:
      </div>
      <input type="email" required/>
  </div>  

  <div class="col-md-4"> 
      <div class="left">
        Password:
      </div>
     <input type="password" required/>
   </div>
</div>
</form>
      </div>
    </div>

Check out the JsFiddle demo. The layout adjusts responsively based on screen size, stacking vertically when small and horizontally otherwise. To prevent vertical stacking, consider using col-xs-6 instead of col-md-6.

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

``There Seems to be an Issue with Loading Content in Tabs

Hey! I'm encountering an issue with my jquery tabs. The first tab content loads fine, but when I select another tab, the content doesn't display. Then, when I try to go back to the first tab, it doesn't load either. Here's the HTML cod ...

Struggling with aligning rows containing three divs each in Rails and bootstrap

Looking to display 3 article divs in each row on my website using bootstrap 3 grid system: <div class="container-fluid"> <h1>NEWS</h1> <div class="row"> <% @articles.each do |article| %> <div class="col- ...

Using AngularJS to incorporate ng-include with ng-click functionality

I am trying to figure out a way to insert HTML that is specifically optimized for the controller into an alert div. Unfortunately, I have been unsuccessful so far... <script type="text/ng-include" id="login.html"> <form data-select="exepti ...

Injecting CSS styles into a webpage using a Chrome extension before the page has completely loaded to achieve instant customization

As a newcomer to creating Chrome (or other browser) extensions, I am working on developing one that applies custom CSS rules to specific page elements. Overall, it seems to be functioning as intended, but with some minor issues. One issue I have encounter ...

Is there a way to retrieve all "a" tags with an "href" attribute that contains the term "youtube"?

My goal is to capture all a tags that have the href attribute containing the word youtube. This task requires the use of jquery. ...

Questions about syntax: What is the correct course of action?

If there is a child inside a div with an id, such as id="mother", how should the css be written correctly? Example: 1) #mother ul li {...} or 2) .mother ul li {...} Is there a difference? The second example I came across when MOTHER had a class name, ...

When you hover over them, Material UI icons shrink in size due to the Border

I've been working on a React application that includes Material UI icons in the header. My goal is to add a border at the bottom of each icon when hovered over, but currently, the borders are too close to the icons. Another problem I'm facing is ...

Is it possible to use an onclick function to input JavaScript values into a password entry box seamlessly?

Is there a way to input password values continuously using a JavaScript onclick function into a password field? I have two images, one 'Blue' and one 'Red', that trigger an onclick function with the following values: Blue= w3! Red= T4 ...

Issue with CSS background scaling bug

Is it possible to make the cloud background scale within the box? The current issue can be viewed here: I have tried various methods to resolve the problem where the background scales even beyond the limited box. However, I could not identify the solutio ...

What is the best way to ensure HTML validation during a pull request?

Are there any tools available to validate all specified files in a pull request? I have previously used Travis CI for testing and am now searching for a similar plugin focused on validation rather than tests, such as W3C validation. ...

Convert a form into plain text utilizing CSS with minimal usage of jQuery or Javascript

I am working on an HTML page which has a form with various tags such as checkboxes, dropdowns, and more. When a button is clicked, I want to display the same form as plain text in a popup using jQuery dialog. Currently, I have managed to show the form in ...

How can I include a ?ref query parameter in a URL when linking from external websites?

I've always wondered about how websites are able to include the ?ref parameter in their URLs when they are referred from another website. Do both sites need to incorporate this into their code? How does this function exactly? ...

Attempting to deactivate the bootstrap-fullscreen-select feature using JavaScript

Currently, I am in the process of developing a Python Flask server to manage a project that I have undertaken. While exploring different options, I came across bootstrap-fullscreen-select which turned out to be exactly what I needed for my control page. H ...

JavaScript tool: Verify the presence of both jQuery and jQuery UI

I have been working on developing a Javascript Widget (almost complete), and when integrating it into the first site I encountered some issues. My Widget requires loading multiple libraries (jquery, jquery ui, mustache, ...); this is achieved by injecting ...

Adding a border around the `<tr>` elements in a table

How can I add a border to the <tr> element (t_border), without the inner table inheriting the style from the outer one? <table> <tr> <td>A</td> </tr> <tr> <td> <ta ...

How can two unique links toggle the visibility of divs with two specific IDs?

I am developing an interactive questionnaire that functions like a 'create your own adventure' story. The questions are shown or hidden depending on the user's responses. Below is the HTML code: <!-- TIER 3 ============================== ...

What steps do I need to take to transform this HTML snippet into a Bootstrap design

Looking to convert the table below into bootstrap rows and columns. I'm not very familiar with bootstrap, but would like to give it a try. Any guidance on where to start would be greatly appreciated. Thank you for your help! <div id="section1"> ...

Utilize HTML5 local storage to highlight a specific row in a table

Currently, we are in the process of developing a code that involves marking table rows using HTML5 local storage and jQuery. Below is the initial code snippet... $(document).ready(function () { $('table tbody tr').click(function() { ...

Switching between three div elements along with two icons can be done by using toggle functionality

Is there a way to make the icon change back when clicked again without making major changes to the existing code? Looking for suggestions on how to achieve this functionality. function myFunction() { var element = document.getElementById("demo"); el ...

What could be causing my PrimeReact dropdown component to ignore the custom class styles?

Within my Project, I am utilizing multiple Prime React dropdown components and I am aiming to customize one of them with a unique style. In my CSS, I have established global styles to overwrite the default settings for all the dropdowns. However, when tryi ...