Creating a three-column HTML form layout solely with CSS, and steering clear of any libraries or dependencies, is a task

Is there a way to implement a three-column HTML form layout according to the design depicted in the linked image?

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

Shown above is the sample HTML code for the template. What I am looking for is the proper CSS styling to achieve a consistent look and feel.

<form method="post" name="Form1" action="" onSubmit="return validateForm();" onchange="showForm();" id="form3118" >
  

         <div class="webform-component first-name" >
            <label for="field0" >
              First Name*
            </label>
            <input id="field0" name="firstName" type="text" value="" />
          </p>
        </div>

          <div class="webform-component last-name" >
            <label for="field1">
              Last Name*
            </label>
            <input id="field1" name="lastName" type="text" value="" />
          </p>
        </div>
    

        <div class="webform-component school" >      
            <label for="field2">
              School*
            </label>
            <input id="field2" name="schoolName" type="text" value="" />
        </div>

<div class="webform-component role" >    
            <label for="field3">
              Role*
            </label>
            <select id="field3" name="role">
              <option value="" selected="selected" >
                Please select
              </option>
              <option value="Principal" >
                Principal
              </option>
              <option value="Assistant/Vice Principal" >
                Assistant/Vice Principal
              </option>
              <option value="Curriculum Coordinator" >
                Curriculum Coordinator
              </option>
              <option value="eLearning Coordinator" >
                eLearning Coordinator
              </option>
              <option value="Head of Department" >
                Head of Department
              </option>
              <option value="Teacher" >
                Teacher
              </option>
              <option value="Other school staff member" >
                Other school staff member
              </option>
              <option value="None of the above" >
                None of the above
              </option>
            </select>  
</div>       

        <div class="webform-component  email-address" >          
            <label for="field5" >
              Email Address*
            </label>
            <input id="field5" name="emailAddress" type="text" value="" />
        </div> 


         <div class="webform-component  last-name" >
            <label for="field15">
              Mobile/Phone number*
            </label>
            <input id="field15" name="mobile" type="text" value="" />
          </p>
        </div>

         <div class="webform-component--resource-format" >
            <label for="field13" >
              In what format do you prescribe resources?
            </label>
            <select id="field13" name="resourceFormat" >
              <option value="" selected="selected" >
                Please select...
              </option>
              <option value="Digital only" >
                Digital only
              </option>
              <option value="Digital with some print" >
                Digital with some print
              </option>
              <option value="Equal digital and print" >
                Equal digital and print
              </option>
              <option value="Print with some digital" >
                Print with some digital
              </option>
              <option value="Print only" >
                Print only
              </option>
            </select>
          </div>

     

            <input type="submit" value="Submit"  />
          
  </form>

While it's easier to use CSS flex/grid or Bootstrap for this layout, the preference is to use pure CSS for universal browser compatibility without encountering any rendering issues.

Answer №1

Even though I recommend exploring flex or grid for this particular situation since they are both pure CSS and widely supported, I understand that you are unable to use them.

Alternatively, a widely supported option is inline-block.

The provided code is straightforward, dividing the section into 7 parts, with the first six being equal in width and the 7th being double their width.

By utilizing percentages, you can distribute the width of the body (or container) to accommodate 3 inline divs along with their margins.

This code snippet lays the foundation, but you will need to make decisions regarding the heights, paddings, placeholders, dropdown options, submit button formatting, responsiveness for narrow screens, and other customization features.

It is advisable to view the snippet in full screen mode and progressively reduce the width to ensure proper accommodation for border and padding widths.

* {
 margin: 0;
 padding: 0;
 box-sizing: border-box; 
}
body {
  background-color: #522464;
}
[class^="webform-component"] {
  display: inline-block;
  margin: 1.5%;
}
.webform-component {
  width: 30%;
}
.webform-component--resource-format {
  width: 60%;
}
label {
  color: white;
  background-color: #522464;
  font-variant: small-caps;
  display: block;
  padding-left: 1em;
}
input, select {
  border: 1px white solid;
  border-radius: 3vmin;
  background: #522464;
  width: 100%;
  height: 3em;
  color: rgba(255, 255, 255, 0.4);
}
<form method="post" name="Form1" action="" onSubmit="return validateForm();" onchange="showForm();" id="form3118" >
  

         <div class="webform-component first-name" >
            <label for="field0" >
              First Name*
            </label>
            <input id="field0" name="firstName" type="text" value="" placeholder="First name"/>
          </p>
        </div>

          <div class="webform-component last-name" >
            <label for="field1">
              Last Name*
            </label>
            <input id="field1" name="lastName" type="text" value="" />
          </p>
        </div>
    

        <div class="webform-component school" >      
            <label for="field2">
              School*
            </label>
            <input id="field2" name="schoolName" type="text" value="" />
        </div>

<div class="webform-component role" >    
            <label for="field3">
              Role*
            </label>
            <select id="field3" name="role">
              <option value="" selected="selected" >
                Please select
              </option>
              <option value="Principal" >
                Principal
              </option>
              <option value="Assistant/Vice Principal" >
                Assistant/Vice Principal
              </option>
              <option value="Curriculum Coordinator" >
                Curriculum Coordinator
              </option>
              <option value="eLearning Coordinator" >
                eLearning Coordinator
              </option>
              <option value="Head of Department" >
                Head of Department
              </option>
              <option value="Teacher" >
                Teacher
              </option>
              <option value="Other school staff member" >
                Other school staff member
              </option>
              <option value="None of the above" >
                None of the above
              </option>
            </select>  
</div>       

        <div class="webform-component  email-address" >          
            <label for="field5" >
              Email Address*
            </label>
            <input id="field5" name="emailAddress" type="text" value="" />
        </div> 


         <div class="webform-component  last-name" >
            <label for="field15">
              Mobile/Phone number*
            </label>
            <input id="field15" name="mobile" type="text" value="" />
          </p>
        </div>

         <div class="webform-component--resource-format" >
            <label for="field13" >
              In what format do you prescribe resources?
            </label>
            <select id="field13" name="resourceFormat" >
              <option value="" selected="selected" >
                Please select...
              </option>
              <option value="Digital only" >
                Digital only
              </option>
              <option value="Digital with some print" >
                Digital with some print
              </option>
              <option value="Equal digital and print" >
                Equal digital and print
              </option>
              <option value="Print with some digital" >
                Print with some digital
              </option>
              <option value="Print only" >
                Print only
              </option>
            </select>
          </div>

     

            <input type="submit" value="Submit"  />
          
  </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

Eliminate XML namespaces from HTML content generated through XSL in PHP

In my PHP routine, I am utilizing XSL to convert XML into HTML. The issue I am facing is that xmlns namespaces are being added as attributes to the h2 element during the transformation process. PHP: $url = "http://www.ecb.europa.eu/stats/eurofxref/eurofx ...

Adjust the div height to 100% in Bootstrap to center text, even with the presence of a navbar

I'm currently using Bootstrap 5 and facing an issue with getting text centered vertically on the page. I attempted to make the container of the div take up 100% of the page by using h-100, but it resulted in overflow due to the navbar occupying some s ...

Tips for including an external babel JS (ES6) file in an HTML document:

To include the babel js file in an HTML file, take a look at the code snippet below: <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script> <script src="https://cdnjs.cloudfl ...

Is it feasible to place an image on top of a box?

Hello everyone, I have been trying to figure out how to achieve a specific layout in React. I am using MUI so there is no need for any hard-coded CSS. However, my attempts have not been successful so far. The layout I am aiming for consists of an image on ...

I am experiencing an issue where certain HTML classes are not applying the CSS code properly within my PHP file

I am facing an issue with my code where some of the HTML classes are not applying the CSS styles correctly, such as the first class "class="foot"". Below are the files that I have: * { margin: 0%; padding: 0%; ...

Styling menus with CSS

I'm struggling with a CSS issue while attempting to add a 1px solid black line after each element in my drop-down table menu. The current appearance of my menu is causing some trouble. What I desire for it to look like involves applying border: 1px s ...

Switching the arrow direction in Bootstrap 4 menu toggles

I'm a beginner with Bootstrap 4. My navigation menu includes a dropdown item with the standard caret pointing down, added automatically by Bootstrap. Now, I want to make the caret point up after opening the dropdown menu for the nav item. Despite ext ...

Retrieve information from a SQL database table and present the output in an HTML table format

I am trying to display the result of a query to a remote ODBC SQL database in an HTML table using PHP. I have successfully established the connection with the database, but when I attempt to execute a query and display it in a table, nothing appears. I am ...

Tips for adjusting the font size options within the Autocomplete feature of Material UI Version 5

Is there a way to adjust the font size of the drop-down items? I have tried various methods to change the font size, including: How do I change Material UI Autocomplete font size? How to change fontsize of options in Material ui autocomplete? Unfortuna ...

Center Your Text Vertically on Google Sites

Trying to spice up my Google Sites page, I decided to take matters into my own hands and customize the banner at the bottom of the site. My goal was to create an orange rectangle with two lines of text perfectly centered both horizontally and vertically. D ...

What could be causing the CSS not to load on my WordPress website?

In an effort to improve my page speed score, I decided to install several plugins. Unfortunately, after installing w3 total cache, my website stopped loading CSS properly. Check out this image of the website ...

Keep an ear out for upcoming occasions once the transition has been completed

I am looking to create a smooth transition effect that will push the main content downwards when the Twitter Bootstrap collapse menu is activated using the toggle button. However, I have noticed an issue where if I quickly double click the toggle button, ...

Instant feedback from dynamically generated text boxes

As a Python developer, I am venturing into the realm of HTML. Currently, I am working on an internal tool that enables users to create directories for various projects. To achieve this, I have implemented a method for dynamically adding and removing text b ...

What is the best way to have my items fill the entire column space using flexbox?

Having 2 containers and wanting them to have the same height has been a challenge. I've been experimenting with flexbox and the flex-direction: column (flex-column) property, but I can't seem to get each element to divide the available container ...

What is the reason for a newly created custom class to have priority over a class with a different name from an earlier loaded file?

Utilizing Bootstrap 4 from the CDN, I have created a new class named: .pt-10 { padding-top: 10rem !important; } The css files are loaded in the following order within the html document: <link href="bootstrap cdn css..."> <link href="my file"> ...

Hamburger Menu in Bootstrap not functioning as expected

Despite following each step meticulously for implementing the Hamburger menu in the navbar, I encountered an issue. The navbar collapses when resizing the window but fails to open upon clicking it. Below is a sample code snippet for reference. It utilizes ...

Reordering columns in WHMCS Template using Bootstrap 4

Currently in the process of redesigning my website's theme powered by WHMCS with Bootstrap 4. I am facing challenges in implementing column ordering in the client area similar to the default "six" template in Bootstrap 3. The goal is to have the Prima ...

Troubleshooting problem with Bootstrap Modal inputs and header tags

When it comes to the button that says data-whatever="Add a recipe", I think it is causing my input placeholders to be overridden, and I'm not sure why. If I remove it, everything works but the h5 header for the new recipe will be blank. <button ...

Link PayPal payments to the individual making the payment

On my website, I offer in-game features that can be purchased through a miniature store with PayPal buy now buttons. I'm looking for the best and most secure method to automatically deliver these in-game bonuses to users after they have completed thei ...

Image not displaying on rn-carousel

I am currently using an rn-carousel for image sliding but I am encountering an issue where the images are not displaying on the screen after building the app on a device. Can anyone provide some suggestions on what I should do to rectify this issue? Your h ...