How can I organize the form input fields into two columns?

I'm currently working on a project that involves using a form for project-based learning. However, I'm having trouble getting the form input to display in two columns. To achieve this, I've set up a main div called "container" with two nested divs inside it - "left" and "right". I've used the float property to align these divs next to each other. The left div displays a background image while the right div contains the form. My goal is to structure the form into two columns - with first name and last name in the first column, email and telephone in the second column, and password and confirm password in the third column. I tried using the flex property but couldn't get it to work. Any suggestions on how to achieve this two-column layout for the form?

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="main.css" type="text/css">
    <title>Document</title>
</head>

<body>

    <div class="container">
        <div class="left">
            <div class="bg">
                <img src="odin-lined.png" alt="">
                <h1>ODIN</h1>
            </div>
        </div>

        <div class="right">
            <p>This is not a real online service! Lorem ipsum dolor sit amet consectetur, adipisicing elit.
                Necessitatibus, commodi!

                Sign up now to get started.</p>




            <form action="">
                <div class="input">
                    <label for="first name">FIRST NAME</label>
                    <input type="text">
                </div>
                <div class="input">
                    <label for="last name">LAST NAME</label>
                    <input type="text">
                </div>
                <div class="input">
                    <label for="email">EMAIL</label>
                    <input type="email">
                </div>

                <div class="input">
                    <label for="telephone">TELEPHONE</label>
                    <input type="tel">
                </div>

                <div class="input">
                    <label for="password">PASSWORD</label>
                    <input type="password">
                </div>
                <div class="input">
                    <label for="password">CONFIRM PASSWORD</label>
                    <input type="password">
                </div>
            </form>

        </div>
    </div>

</body>

</html>

Here is the CSS

.

.left{
    float: left;
    width: 50%;
}

.right{
    float: right;
    width: 50%;
 
}


.bg{
    background-image: url('background.jpg');
    background-size: cover;
    background-repeat: no-repeat;
    height: 100vh;
    width: 500px;
}


.bg img{
    width: 150px;
    height: 150px;
    margin: 40px;
}

Answer №1

Your code has been corrected. I recommend learning how to use display flex as it is not difficult but very useful. One change that was made is the path to the CSS file in the head tag, make sure to update that for everything to work properly. You can also review how the issue was resolved. :D

For your specific situation, using the placeholder attribute with placeholder="Example" would present a better look, and using labels may cause some minor issues.

Here is the updated code:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css" type="text/css">
    <title>Document</title>
</head>

<body>

    <div class="container">
        <div class="left">
            <div class="bg">
                <img src="odin-lined.png" alt="">
                <h1>ODIN</h1>
            </div>
        </div>

        <div class="right">
            <p>This is not a real online service! Lorem ipsum dolor sit amet consectetur, adipisicing elit.
                Necessitatibus, commodi!

                Sign up now to get started.</p>




            <form action="">
              <div class="col">
                <label for="first name">FIRST NAME</label>
                <input type="text">

                <label for="last name">LAST NAME</label>
                    <input type="text">
              </div>


              <div class="col">
                <label for="email">EMAIL</label>
                    <input type="email">

                    <label for="telephone">TELEPHONE</label>
                    <input type="tel">
              </div>

              <div class="col">
                <label for="password">PASSWORD</label>
                    <input type="password">

                    <label for="password">CONFIRM PASSWORD</label>
                    <input type="password">
              </div>
                

                
            </form>

        </div>
    </div>

</body>

</html>




.left{
  float: left;
  width: 50%;
}

.right{
  float: right;
  width: 50%;

}


.bg{
  background-image: url('background.jpg');
  background-size: cover;
  background-repeat: no-repeat;
  height: 100vh;
  width: 500px;
}


.bg img{
  width: 150px;
  height: 150px;
  margin: 40px;
}

.col{
  display: flex;
  margin-right: 30px;
}

.col label{
  width: 180px;
}

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

What is the method for altering the text color within a disabled input field?

Currently facing difficulty in changing the color of the text within the input field when it's disabled. I'm utilizing Material UI for this purpose. import React from "react"; import { makeStyles } from "@material-ui/core/st ...

How can I establish default values for 2 to 3 options in a Dropdownlist?

Is there a way to set two values as default in a dropdown list, and when the page is refreshed, the last two selected values are retained as defaults? Thanks in advance! Visit this link for more information ...

Choose the singular Element lacking both a class or an ID

I came across this and that question, however, they are both focused on Javascript. I am searching for a way to target the lone div that does not have an ID or Class assigned to it. For instance: <body> <div class="X" ... /> <div class="Z ...

Switch up your Wordpress gallery images with a simple mouseover trick!

Hey there! I need to create a grid of images for various products, where each item in the grid has 2-3 images but only the first one is visible initially. I want the other images to loop on mouse hover. Do you know how to do this in WordPress? My initial ...

Tips for adjusting the font size in table cells based on the content within them

In my HTML table, I have numbers incrementing from 0 in each cell, arranged from left to right and top to bottom. I have set the width and height of the cells using CSS (with dimensions of 40px width and 25px height). As the table grows larger, the numbe ...

The common CSS technique using the before pseudo class is failing to address the issue of content disappearing behind the page

I've been struggling with implementing CSS code in my main stylesheet file. I followed the advice online to use the ::before pseudo class to align the height and margin with the header. However, even after making these adjustments, the content still a ...

Common Error for Novice HTML/CSS Learners

I am currently enrolled in an introductory web design course on Treehouse, and I have encountered a problem with centering a class in HTML using CSS. Despite following the instructions closely, my code is not displaying correctly. Can someone please review ...

immediate removal upon pressing the button

Struggling to remove data from a datatable when clicking the delete button for quick admin side action. My code isn't functioning properly, even after attempted fixes. Here's my code: <div class="table-responsive"> <table id="datas" cl ...

Hide the form field upon button click

I currently have a form with 6 input fields all under the same id entry1. Whenever I click the Add Section button, these fields are cloned and added to the form. There is also a button for removing the section above. The issue arises when I click on the R ...

Sluggish JQuery Animation When Key is Pressed

I have a situation where I am using JQuery to create animation effects on a div element based on arrow key inputs. However, I am encountering an issue where the animation slows down significantly each time I repeat pressing the arrow key for the current d ...

Struggling to make the label and input function properly when focused

I'm looking to have the label displayed on top of the input field. However, when I rearrange the code to achieve this, the CSS Focus styles no longer work properly. Specifically, I want the label to enlarge when the input field is focused. Any ideas o ...

A guide to extracting data from HTML tables using Python for web scraping and exporting the results to

My Python skills are still pretty basic, but I'm working on creating a web scraping tool to extract data from an HTML table online and save it into a CSV file with the same structure. Here's an example of the HTML table (I'll show just a fe ...

What caused the slide show to malfunction during the live preview?

1-Why is the slide show not working in the live preview? It works on my desktop, but when I share it in the live preview, it doesn't work. <div class="slide-show-content"><!-- /image gallery slideshow--> <div class="slide-show-default ...

Increase the size of an image when the mouse hovers over it within a

Recently, I came across this tutorial on creating a zoom in effect for images when hovering over them with the mouse. The tutorial doesn't use tables to display the images, so I was wondering if I could achieve the same effect by placing the images in ...

Transform inline styles in React to CSS declarations

Is there a tool available that can convert React inline style descriptions into CSS rules? For example: { minHeight: 200, position: 'relative', flexGrow: 1, flexShrink: 1, display: 'flex', flexDirection: ' ...

Align the bottom of an image with the top of text to achieve perfect vertical alignment

My goal is to arrange numerous images in a row, with text displayed below each image. Each block of text may consist of multiple lines and should be centered. While the heights of the images may vary, their widths will remain consistent. It is important th ...

Avoid floating right elements all the way up if there are already elements floating left

I am struggling to position block 5 next to block 3 on larger screens, while maintaining the desired arrangement on smaller viewports. The blocks do not have fixed heights in my setup. You can see my codepen for a better understanding of what I'm try ...

Consistently scaling the Embla carousel slides for a seamless presentation experience

In my current project, I am utilizing Embla Carousels and aiming to incorporate a smooth slide scaling effect as users scroll through. The idea is for slides to enlarge the closer they get to the left edge of the carousel container, then decrease in size r ...

Enabling Autoplay for HTML Videos on Safari iOS 14.2

Recently, I've observed that my autoplay videos are not functioning on iPhone iOS 14.2. Surprisingly, everything was working fine prior to this version. Is there anyone familiar with a solution or workaround for this issue? Perhaps there's a met ...

Is there a way to change the labels of checkboxes within a table that is created dynamically?

I am new to JavaScript/jQuery and facing an issue with modifying checkbox labels in a dynamically generated table. <td> <input type="checkbox> <b>$18,000.00</b> ($18000+) Diamond Sponsor<br> <input type="checkbox> <b ...