Is there a way for me to make the two form fields expand and fill the gap between them?

I've created a form with the first name and last name fields displayed horizontally next to each other, as shown in the image. When a user clicks on a field, it should change color (still pending coding).

However, there seems to be an unwanted gap between the First Name field and the Last Name field in the layout presented in the image. I'm struggling to identify the source of this issue.

How can I eliminate this gap so that the fields take up all available space?

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

The HTML:

    <div class="topBox">
        <div class="closeModal">X</div>
        <div class="clear"></div>
        <div><img src="images/ProvenWordLogoSmall.png" alt="ProvenWord Logo"></div>
    </div>
    <div class="bottomBox">
        <h3>Free Quote Form</h3>
        <form class="freeQuoteForm">
            <div class="nameFields">
                <input type="text" id="firstName" placeholder="First Name" required>
                <input type="text" id="lastName" placeholder="Last Name" required>
            </div>
            <div class="nameFields">
                <input type="email" id="email" placeholder="Email Address" required>
            </div>
        </form>

    </div>
     <script type="text/javascript" src="main.js"></script>         
</body>

The CSS:

.topBox {
    width: 640px;
    margin: 0 auto;
}

.bottomBox {
    background: white;
    margin: 30px auto;
    width: 640px;
    height: 595px;
    border: 1px solid #9c9c9c;;
}

.bottomBox h3 {
    text-align: center;
    padding: 20px 0;
}

.freeQuoteForm {
    width: 530px;
    height: 430px;
    border: 1px solid #9c9c9c;
    text-align: left;
}

input, textarea {
    font-family: "Sinkin Sans", Verdana, Helvetica, sans-serif;
    font-size: 12px;
    font-weight: 100;
    border: none;
}

input[type="text"], input[type="email"] {
    display: inline-block;
    width: 262px;
    height: 60px;
    padding: 0px;

}

input[type="email"] {
    width: 518px;
}

#lastName {
    border-left: 1px solid #9c9c9c;
}

.nameFields {
    border-bottom: 1px solid #9c9c9c;
}

Answer №1

I have utilized percentages for the input fields. The 'last name' field has a border, so it was necessary to apply box-sizing: border-box; to prevent it from dropping down to the next line.

.bottomBox {
    background: white;
    margin: 30px auto;
    width: 640px;
    height: 595px;
    border: 1px solid #9c9c9c;
    background: lightblue;
}

.bottomBox h3 {
    text-align: center;
    padding: 20px 0;
    background: cornflowerblue;
}

.freeQuoteForm {
    width: 530px;
    height: 430px;
    border: 1px solid #9c9c9c;
    text-align: left;
    background: skyblue;
}

input, textarea {
    font-family: "Sinkin Sans", Verdana, Helvetica, sans-serif;
    font-size: 12px;
    font-weight: 100;
    border: none;
}

input[type="text"] {
    display: inline-block;    
    height: 60px;
    padding: 0px;
}

input[type="email"] {
    height: 60px;
    padding: 0px;
}

#lastName, #firstName {
  padding-left: 5px;
  width: 50%; 
  box-sizing: border-box;
}

#email {
  padding-left: 5px;
  width: 100%;
  box-sizing: border-box;
}

#firstName:focus, #lastName:focus, #email:focus {
  background: paleturquoise; 
}

#lastName {
  margin-left: 0px;
  border-left: 1px solid #9c9c9c;
}

.nameFields {
  border-bottom: 1px solid #9c9c9c;
}
<div class="bottomBox">
<h3>Free Quote Form</h3>
<form class="freeQuoteForm">
<div class="nameFields"><input type="text" id="firstName" placeholder="First Name" required><input type="text" id="lastName" placeholder="Last Name" required></div>
<div class="nameFields">
<input type="email" id="email" placeholder="Email Address" required>
</div>
</form>
</div>

Answer №2

Have you ever encountered the line break issue when dealing with inline elements?

Learn how to eliminate the gap between inline-block elements here.

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

The value property of the input element is returning as undefined

The input value entered is always returning undefined. Despite trying various solutions found in similar questions, my jQuery code continues to return undefined. jQuery: $( document ).ready(function() { $('#Input').keypress( function(e ...

Setting the background color for a div in Vue.js when importing HTML

Check out this HTML code snippet <!DOCTYPE HTML> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Getting Started: Serving Web Content< ...

Tracking the User Interface efficiency of a Java Applet running on a website

I have developed a Java Swing based messenger applet that runs smoothly on browsers. My next step is to host this applet on a webpage and allow users to test it out. I want to track the time they spend on each task while using the messenger, as well as any ...

What's the Best Way to Add a Border to My Two-Column Form?

I'm currently working on a reservation form for my website with a 2-column layout. In one column, I have tables, and I've been trying to add a divider between the columns but haven't found a solution yet. Despite researching ways to add a d ...

The CSS background and background-image are visible exclusively on the Chrome desktop browser

Why is the background image not showing up on my website? The img src is also not displaying. All pictures show up fine on Chrome desktop browser, but not on Chrome mobile browser. Other browsers that are not displaying the images include Safari mobile, I ...

When a user clicks on an image, I would like to dynamically resize it using a combination of PHP

Although I have a good understanding of CSS and HTML, my knowledge of Javascript is limited. I am looking to add an interactive element to my website where an image enlarges gradually when clicked and smoothly moves to the center of the screen in one con ...

Discover the process of transitioning your animations from Angular to CSS

I have successfully implemented a fade-in/out animation using @angular/animation, but now I am looking to transfer this animation to CSS and eliminate the dependency on @angular/animation. Here is my current animation setup (triggering it with [@fadeInOut ...

JavaScript problem with hovering action causing additional buttons to appear

Currently, I am developing a user interface where, upon hovering over an LI element, 2 buttons appear to provide additional functionality - "edit" and "remove". However, I am facing challenges with the mouse hit zones. The mouseover function works effect ...

Utilize jQuery to apply a border and background color to a table row when hovering over it

Is there a way to change the border of a table row along with its background color when the mouse hovers over it? Currently, I can only modify the background color using the following code: $(document).ready(function() { $(function() { $(&apos ...

What could be causing the bottom of a vertical scroll bar to be cropped in Internet Explorer 11?

I am experiencing an unusual problem in IE11 where the content at the bottom of my page is being cut off along with the scroll bar that should allow for viewing that content. I have managed to resolve this issue in Chrome, Firefox, and Edge but I cannot se ...

Increase the size of the embedded iframe in your Cordova application by using the pinch-to-zoom

I have been struggling with this issue for the past few days and am having trouble finding a solution.. I am trying to figure out how to embed an iframe in a cordova app (running on an iOS device) to display an external webpage while allowing users to pin ...

Guide on creating a darkening effect for lights

Seeking assistance on how to create a light-off effect when clicking on any of my textboxes. I discovered this concept on the following website: What I aim to achieve is that upon clicking a specific textbox, it will be highlighted. Upon clicking the sam ...

Pressing a button meant to transfer text from a textarea results in the typed content failing to show up

Having trouble with a custom text area called a math field. I'm currently interning on a project to build a math search engine, where users can input plain text and LaTeX equations into a query bar. The issue I'm facing is that sometimes when th ...

I'm having trouble getting my HTML button to redirect to a PHP link

I'm attempting to call a PHP script from my HTML file. Here's the snippet of my HTML code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://w ...

Internet Explorer 11 has a problem with excessive shrinking of flex items

I have a flexbox setup with a left and right section, each of equal width. The left side displays an image and the right side contains text. While this layout works fine in Google Chrome, it does not wrap properly in Internet Explorer 11 when the width is ...

Issue with the alignment of DIV container due to spacing issues

In the screenshot below, there is a DIV container with padding of 15px on the left and right. However, the contents are appearing spaced out downwards for some reason... Other than the left & right padding, no other styling seems to be affecting it. Adjus ...

Creating an SVG element that adjusts to the size of its parent container: tips and tricks

I'm attempting to achieve the following: Displaying an SVG square (with a 1:1 aspect ratio) inside a div element. When the width of the div is greater than its height, the square should adjust to fit within the container based on the height (red box ...

I am looking to pair a unique audio clip with each picture in my collection

I have implemented a random slideshow feature that cycles through numerous images. I am now looking to incorporate a brief audio clip with each image, synchronized with the array I have established for the random pictures. The code snippet below is a simil ...

What is the best way to access a local variable within a POST method in Node.js?

Below are some of the modules that I have utilized: const mysql = require('mysql'); const express = require('express'); const session = require('express-session'); const path = require('path'); const bodyParser = req ...

Setting fixed width for table headers in Bootstrap 3

Can someone explain why the width of "th" is not fixed and new line breaks occur when the content is too big? Currently, the "th" width expands. How can this be fixed? The width of my first column is col-lg-2. Click here for an example image ...