How to Align Two HTML Forms Using CSS

I've been experimenting with various methods, but I'm still unable to achieve the desired outcome.

Currently, my setup looks like this:

https://i.sstatic.net/fUXKr.png

However, what I really want is something more like this:

https://i.sstatic.net/VYYgX.png

The layout consists of a #Container div that contains two forms: #Form1 for profile picture customization and #Form2 for personal details such as name, email, and website.

My goal is to have the profile picture aligned on the left, followed by the text fields for first name, last name, and email. Once the bottom of Form1 is reached, Form2 should appear aligned to the left side as illustrated in the image.

For example, if I set #Form1 to 30% width and Form2 to 60%, it should look like this:

https://i.sstatic.net/jJZIF.png

I've attempted positioning #Form1 as relative and #Form2 as absolute, but so far, I haven't achieved the correct result.

This is the CSS I'm currently using:

#Form1 {
    width: 30%;
    float: left;
    margin-top: 15px;
}
#Form2 {
    width: 60%;
    float: left;
    margin-top: 15px;
}

Here's a sample snippet of the HTML code:

<div id="container">
    <form id="form1">
    <!-- Content of Form1 -->
    </form> 
    <form id="form2">
    <!-- Content of Form2 -->
    </form> 
</div>

Answer №1

To achieve the desired result, you can set form1 to be positioned absolutely and break up form2 into multiple divs (while still within the same parent form). Here is an example:

div {
  box-sizing: border-box;
}
#container {
  position: relative;
}
#Form1 {
  padding: 5px;
    width: 30%;
    height: 50%;
    background-color: red;
    position: absolute;
}
#Form2 {
    width: 60%;
    height: 300px;
}

form {
  display: inline;
}

#Form2 .top {
  padding: 5px;
  margin-left: 50%;
  background-color: yellow;
  height: 50%;
}

#Form2 .bottom {
  padding: 5px;
  height: 50%;
  background-color: yellow;
}
<div id="container">
  <div id="Form1">
    <form>
     form 1
    </form>
  </div>
  <div id="Form2">
    <form>
      <div class="top">content of form 2</div>
      <div class="bottom">other content of form 2</div>
    </form>
  </div>
</div>

Answer №2

For content to align at the bottom, you will need to insert an additional <div> in the bottom section.

#form1 {
    width: 68%;
    padding-left: 32%;
    height: 100vh;
    background: aliceblue;
}
#form2 {
    position: absolute;
top: 0;
left: 0;
    width: 30%;
    height: 500px;
    background: beige;
}
<div id="container">
    <form id="form1">
    <!-- Content of Form1 -->
    </form> 
    <form id="form2">
    <!-- Content of Form2 -->
    </form> 
</div>

Answer №4

Check out this solution where you can use a container to wrap both forms with form1 floating left and the second form wrapping naturally:

<div class="container">
  <div class="left">
    <input type="text">
    <input type="text">
  </div>
  <div class="right">
    <input type="text">
    <input type="text">

    <label><input type="text"></label> 
    <label><input type="text"></label> 
    <label><input type="text"></label> 
    <label><input type="text"></label> 
  </div>
</div>

CSS:

.left {
 float: left; 
 width: 300px; 
 border: 1px solid green;
}

.right {
 border: 1px solid blue;
}

input {
 display: block;
 margin: 20px;
}

Here is the link to view it in action on JSFiddle.

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

Ways to differentiate between a desktop browser width of 1024px and a tablet width of 1024px with the help of jquery

So here's the issue I'm dealing with: I have scroll-based animation functions set up for desktop browsers, and different animations in place for tablet browsers. The challenge is to make these functions work on a desktop with a 1024px dimension. ...

Creating a Mobile-Friendly Centered Navigation Bar with Scroll Functionality Using Bootstrap 4 Alpha 6

Currently, I am working with the standard Bootstrap navbar that has the class="justify-content-center". My goal is to make this navbar scrollable when the elements do not have enough space. The issue I'm facing is that I can only scroll to the right a ...

Using Tailwind @apply within an Angular application's CSS file

I've noticed a yellow line appearing under the @apply in my CSS files, even though the styles are being applied correctly to the HTML components. This seems to be happening in every CSS file I use. Can anyone shed light on this issue? Removing these ...

Verification of Form Submission

Looking for some help with web design, specifically regarding cache issues. I have a website where form data is submitted from form.php to buy-form.php. I'm trying to set up a cache error in Google Chrome so that when buy-form.php is accessed directl ...

Unable to access GDrive on Moodle with an iOS device

I have an iframe code that works in Android, but not on iOS when embedded in Moodle. Does anyone know how to fix this issue? <p><iframe src="https://drive.google.com/embeddedfolderview?id=1d-SHXhof2KnyTmMr2GowJuf4bVKFKQg3&amp;usp#list&q ...

Why am I unable to use Register as a prop function?

I am currently exploring react-hook-form for the first time in my project. After going through the documentation and setting up my components with styles, I am now facing an issue with displaying the form data post submission. Introducing the ContactForm ...

Adding AngularJS modules to an HTML file

Recently, I've been diving into the world of AngularJS, but I'm facing a roadblock - my HTML doesn't recognize the angular module I created. It's odd because the bindings work perfectly without involving the module... This is my HTML: ...

When the enter key is pressed in a contenteditable div, line breaks are disregarded

Is there a way to ensure that when the return key is pressed to start a new line for a post, the output actually starts on a new line? I've been having trouble with this and would like to know the most common solution. Check out the demo below for te ...

Error Encountered in jQuery UI SelectMenu

Struggling to integrate the jQuery UI SelectMenu, I keep encountering the same error in the browser console. Below is the HTML Code: <select name="files" id="files"> <optgroup label="Scripts"> <option value="jquery">jQuery.js</ ...

Troubleshooting the non-responsive behavior of Bootstrap's hidden-sm-down

Why are the two images within the <div> with hidden-sm-down still visible on my laptop when I resize the page? I need them to be hidden on small devices for a different menu layout. <div class="row"> <div class="col-m ...

Use ajax to load a webpage into a specific div, then reload the same div after submitting

I have a webpage that includes hyperlinks and a content area with an id of "contentarea" where the results from these hyperlinks are displayed. When a user clicks on the "Search" link, the page search.jsp loads, which contains a submit button and a form ...

Is it possible for my JQueryUI draggable items to smoothly transition into a different overflowing element?

On my iPad, I have two scrollable areas where I kept the overflow to auto, scroll, or hidden to allow scrolling. One section contains unenrolled students, and using JQueryUI with touchPunch, I can drag a student from the unenrolled bin into their appropria ...

clicking on the anchor does not trigger the modal to open

Below is an anchor tag I have set up: <a href="#" data-toggle="modal" data-target="#modalTC">terms and conditions</a> Here is the structure of my modal: <!-- Modal --> <div class="modal fade" id="modalTC" role="dialog"> <di ...

Problems with form functionality in React component using Material UI

Trying to set up a signup form for a web-app and encountering some issues. Using hooks in a function to render the signup page, which is routed from the login page. Currently, everything works fine when returning HTML directly from the function (signup), ...

CSS Tips: Defining Pseudo-Element Sizes

Currently, I am trying to adjust the width of the :before pseudo-element in order to match it with the dimensions of the element itself, specifically an anchor tag. This is part of my goal to create an overlay that completely covers the entire element. As ...

What are some ways to enable text highlighting when it is disabled?

I've encountered an issue with text highlighting in my asp.net web application when using the latest versions of FireFox and Google Chrome. Strangely, pressing CTRL+A also does not work for all input fields. I haven't had the opportunity to test ...

Is there a way to display the next/previous buttons separately from the scroller in my jQuery thumbnail scroller implementation?

Is there a method to display the next and previous buttons outside of the scroller frame when using jQuery thumbnail scroller by manos.malihu.gr? I have attempted to modify the button class in CSS to make them more prominent or visible, but unfortunately ...

Softening the edges of a table

Could you assist me in rounding the corners of my table? I attempted using the basic border-radius, however, it only separated the border at the corners. Do you think this issue is due to my browser (Firefox) or could it be a bug? You can view my Jsfiddl ...

Enable the ability for anchor links to be clickable when the CSS media print format is used to generate

To illustrate: <a href="https://www.google.com">Google anchor link</a> on the website, it displays as: Google anchor link When printed, it shows as: Google anchor link(https://www.google.com) To address this issue, I included in the CSS: ...

Manipulating an HTML <div> element to display its value as a suffix in another <div> within the HTML code

I'm attempting to combine and show text along with content from another <div> as the modal-header, but it's not displaying correctly. When I give an ID to the modal-header, the *&times;* symbol disappears. This is how my modal-header l ...