Is it possible to create a 2-column form with one div element that spans

I created a form using HTML that is divided into two columns for input fields, followed by a 'footer' row containing the form's submit button and additional text.

The current layout of the form looks like this:

 _______________________________
|                               |
| Input 1          Input 2      |
|                               |
| Input 3          Input 3      |    
|                               |
| Submit           Text         |
|_______________________________|

However, I would like to have the Submit button and text aligned to the right side but doing so seems to disrupt my design :/

<div id="form-wrapper">
  <form id="contact_form" method="post" action="url/to/your/server/here">
    <!-- FIRST column floating left -->
    <div class="float-left c1">
      <ul>
        <li>       
          <label for="name" id="name" >Name<span class="required"> *</span></label>
          <input type="text" name="name" placeholder="John Doe" autocomplete="off" required>
        </li>
        <li>
          <label for="telephone" id="telephone" >Contact Number<span class="required"> *</span></label>
          <input type="tel" name="telephone" placeholder="(01225) 123456" autocomplete="off" required>
        </li>
        <li>
          <label for="email" id="email">Email:</label>
          <input type="email" name="email address" placeholder="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="395c41585449555c795c41585449555c175a5654">[email protected]</a>">
        </li>
      </u>
    </div>


    <!-- SECOND column floating left -->
    <div class="float-left c2">
      <ul>
        <li>
          <label for="enquiry">Enquiry:</label>  
          <select id="enquiry" name="enquiry">  
          <option value="general">General</option>  
          <option value="sales">Sales</option>  
          <option value="support">Support</option>  
          </select>
        </li>
        <li>
          <label for="Message" id="Message" >Message<span class="required"> *</span></label>
          <textarea name="message" cols="40" rows="6" required placeholder="Enter your message"></textarea>
        </li>
      </ul>
    </div>       

    <!-- Clearing float elements - this is a sibling of the floated elements -->
    <div class="form_footer">
      <ul>
        <li><span id="required_field">* Required fields</span></li>
        <li><button class="submit" type="submit">Submit</button></li>
      </ul>
    </div>
  </form>
</div>


a { 
    outline: none; 
}

html, body {
    background:url(images/bg.png);
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: Helvetica, Arial, sans-serif;
    font-size: 0.915em;
    line-height: 14px;
    }

#form-wrapper {
    width: 550px;
    display: block;
    background: #f6f4f4;
    border: #d2cece solid 1px;
    }

#required_field {
    float: right;
    padding: 0 40px 10px 0;
    color: #D45252;
    font-size: 11px;
    font-weight: bold;
    font-family: Lucida Sans, Lucida Grande, Lucida Sans Unicode, sans-serif;
    }

.required {
    color: #D45252;
    font-weight: bold;
    }

#contact_form ul li {
    list-style: none;
    position:relative;
    }

input, textarea, select {
    background:url(images/bg.png);
    font-family: Helvetica, Arial, sans-serif;
    display: block;
    margin: 10px 10px 15px 0px;
    resize: none;
    -moz-border-radius: 3px;
    border-radius: 3px;
    }

/* Styling placeholders based on different browsers */  
::-webkit-input-placeholder {  
    color:#CCC;  
}  

input:-moz-placeholder, textarea:-moz-placeholder {  
    color:#CCC;  
}  

input.placeholder-text, textarea.placeholder-text  {  
    color:#CCC;    
} 

/* Styling for submit button */
.submit {
    font-family: Helvetica, Arial, sans-serif;
    }

.float-left {
    float: left;
}

.float-right {
    float: right;
}

/* Clear floats */
.form_footer {
    clear: both;
}

Answer №1

When floating elements are not cleared properly within the parent element, it can lead to a broken layout. This seems to be the issue in your code.

In this case, you have floated the submit button without clearing it in the main parent div, specifically <div id="form-wrapper".

To fix this issue, simply add a clearfix to the wrapper and everything should work fine. I have provided a solution on my jsbin.

I have utilized Nicolas Gallagher's micro clearfix hack for this.

For more information, you can refer to this discussion on Stack Overflow: SO thread.

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

Tips for implementing jquery to add a class to a div element when right-clicking

Click Actions $(document).ready(function(){ $( "div" ).click(function() { $( this ).toggleClass( "class-one" ); //alert('left click'); }); }); Mouse Clicks $(document).ready(function(){ $( "div" ).click(function() { ...

Exploring nested styles within Less to style both parent elements and their children

Is there a way to apply styles to an element and its descendants? For example: .datepick-month-header, .datepick-month-header select, .datepick-month-header input { background-color: black; color: #fff; font-weight: bold; } In some less documentation, I ...

Is there a way to prevent navbar links from wrapping when closed with CSS?

Upon closing my side navbar, I encountered an issue where the links warp to the size of the navbar. I am seeking a solution to keep the links (highlighted in pink in the image below) the same size without warping. Is there a CSS technique to achieve this? ...

Issue with $_SERVER['PHP_SELF'] not functioning properly

Apologies if this question has been asked before, but after searching extensively I couldn't find a solution. Therefore, I am posting here... The issue is that I'm trying to submit values on the same page (using jQuery Mobile UI) and I have used ...

Generate a Bootstrap dropdown button using JavaScript

Can you assist me in generating an HTML button using JavaScript with Bootstrap styling and customization? I have successfully created a Bootstrap button: <div class="dropdown"> <button class="btn btn-secondary dropdown-toggle" type="button" id ...

Fuel Calculation - Unable to pinpoint the error

My JavaScript Code for Calculating CO2 Emissions I'm working on a program that calculates how much CO2 a person produces per kilometer. This is part of my school project and I'm still learning, so please bear with me... I also just signed up on ...

The panel's fullscreen feature crashes when exiting after triggering the 'resize' function

I'm facing an issue with a popup window that automatically goes into fullscreen mode. There are two buttons - one to exit fullscreen and another to simply close the window. When the window is in fullscreen, the exit button works perfectly. However, i ...

What are the steps to customize the HTML formatter in VS Code?

Struggling to craft HTML code at the moment. VS Code underwent an update recently, causing the auto-formatter (Alt+Shift+F) to present different options and override all settings. Any ideas on how I can access that particular file for modification? I have ...

Employ CSS flexbox and/or JavaScript for creating a customizable webpage

I am in the process of developing a basic IDE for an educational programming language that has similarities to Karel the Dog. One major issue I am encountering is creating the foundation HTML page. The IDE consists of 4 main areas: Toolbox (contains but ...

Learn how to utilize Selenium Web Driver with Java to interact with waypoints located within a map canvas on an HTML5 webpage

Struggling with Selenium Web Driver (Java) - How to interact with waypoints on an HTML5 canvas map? I am currently trying to implement drag and drop functionality on a canvas map within an HTML5 page, but I'm facing some challenges. https://i.sstati ...

Elements are randomly glitching out with CSS transitions in Firefox

Chrome is working perfectly for me, but when I switch to Firefox it behaves differently than expected I am attempting to create a simple animation (utilizing transitions) that continuously runs on mouseover and smoothly returns to the starting position on ...

I am facing issues with my submit buttons as they are not functioning

Once I hit the submit buttons, there seems to be an issue with redirecting to another page. Could anyone assist in identifying the error within this code and why my buttons "typ1" and "cod" are not redirecting to the specified location? <?php inc ...

An unusual type of data is being stored in a MySQL database through Navicat Premium while using Django

Recently, I've encountered an issue while trying to insert data from an HTML form into my database. Strangely, upon submission, the values for "gender" and "website rating" get replaced with "on" instead of the actual input provided through the websit ...

Text positioned beneath a toggle switch in html that overlaps

Is there a way to fix the issue of the label on the left side overlapping below the selector switch on my website? I want to ensure that both labels are perfectly distributed on each side of the switch. Here is the code snippet: <div class="ro ...

What is the process for making the default text in a text box appear grayed out?

Hey there! I have this cool idea for a text box. Basically, it starts off with default text but when you hover your mouse over it, the text disappears and you can start typing as usual: If you want to see how it looks like, you can check out this link: N ...

Stylish CSS for your website's navigation

I am facing a challenge with creating a menu for my website. I want it to be positioned on the left side, similar to the image provided below. However, despite writing the code and applying styles as expected, the menu does not display correctly and appear ...

Guide to creating a mouseover effect where a hover div smoothly slides in from the side

Recently, I stumbled upon a WordPress theme that caught my attention: One particular feature that intrigued me was the translucent div that slides over a tile when hovered. After inspecting the page source, I am still unsure of the technique used to achie ...

Choosing the next SELECT element with jQuery

JavaScript document.querySelectorAll('select[id^="_taskAssignedTo_"]').forEach(function(select) { if (select.value === "1") { select.nextElementSibling.querySelector('select[id^="_taskStatus_"]').disabled = false; } }); ...

Ben Kamens has developed a new feature in jQuery Menu Aim where the sub menu will not reappear once it

While exploring Ben Kemens’ jquery-menu-aim, I came across a demonstration on codepen. The code on codepen allows smooth transition from the main menu to the sub menu, but if you move away completely, the submenu remains visible and doesn't disappe ...

Is it possible for CSS to prevent the insertion of spaces?

When filling out a form, I am able to insert spaces in inputs but not in the textarea (which is necessary). Interestingly, inserting spaces in the textarea works flawlessly. <form action="/#wpcf7-f519-o1" method="post" class="wpcf7-form" enctype="mu ...