Increase the overall width of the form boxes to span the entire line at 100% full width

I'm currently working on a form that includes multiple input boxes placed in the same row.

My goal is to set up the email input to occupy one line, while the date, time, and number inputs should be on another line. However, I am facing difficulty in making sure that the date/time/number inputs span exactly 100% of the width of the form.

The percentages specified in the CSS file at the moment are just approximate values, causing the number box's edge not to align vertically with the email input box.

input[type=email] {
  width: 100%;
}
input[type=date] {
  width: 22%;
  margin-right: 15px;
}
input[type=time] {
  margin-right: 15px;
}
input[type=number] {
  width: 11.4%
}
<form>
  Email: <input type="email"><br>
  Date: <input type="date">
  Time: <input type="time">
  Number in Party: <input type="number">
</form>

Answer №1

If you want to achieve this layout using flexbox, take a look at this example

The approach I used was wrapping each line in a div, like so:

<form>
  <div>Email: <input type="email"></div>
  <div>
    <div>Date: <input type="date"></div>
    <div>Time: <input type="time"></div>
    <div>Number in Party: <input type="number"></div>
  </div>
</form>

For the CSS styling, here's what I did:

form{
  display: flex;
  flex-direction: column;
}

form>div{
  display: flex;
}

form>div input{
  flex-grow: 1;
}

form>div>div{
  display: flex;
  flex-grow: 1;
}

Answer №2

You have the ability to customize the <label> element to control the width, padding, and margin of form field labels.

For instance:

label, input {
display: inline-block;
height: 24px;
line-height: 24px;
}

label {
width: 18%;
margin: 6px 0;
padding: 3px 0 3px 3px;
background-color: rgb(227,227,227);
}

input {
width: 80%;
}

input:nth-of-type(n+2) {
width: 13%;
}
<form>
<label for="email">Email:</label><input type="email" name="email" id="email"><br />
<label for="date">Date:</label><input type="date" name="date" id="date">
<label for="time">Time:</label><input type="time" name="time" id="time">
<label for="number">Number in Party:</label><input type="number" name="number" id="number">
</form>

Answer №3

input[type=email] {
  width: 100%;
}
input[type=date] {
  width: 21%;
  
}
input[type=time] {
  width: 21%;
   margin-right:42px;
}
input[type=number] {
 
  width: 20.9%;
    
  
}
<form>
  Email: <input type="email"><br><br>
  Date : <input type="date">
  Time : <input type="time">
  Number in Party : <input type="number">
</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

I am encountering unexpected issues with the functionality of img srcset and sizes

Attempting to enhance the responsiveness of images on my website has led me to discover the srcset and sizes attributes. The objective is clear: If the screen size exceeds 600px or falls below 300px, a 250x250 image should be displayed For sizes in betw ...

Receiving a 502 Bad Gateway error when attempting to request a CSS file via HTTPS

After recently adding SSL to some pages on my website, I encountered an issue when trying to call a secured web page <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <link href="https:/ ...

Challenges Arising from the Reflection of Vectors in Particle Collisions

Could there be a potential math error in my particle collision simulation that I created? You can find the simulation here. The issue seems to be with the separation of particles during collision resolution. Below is a snippet of the code where particles ...

Jquery animate not working properly after closing the div for the first time

I am currently working with a div that utilizes the .animate function. The CSS for the div is set as follows: position:fixed; bottom:-240px; The associated animate script looks like this: $("#media").click(function () { $("#mediadetails").animate({ ...

Creating a showcase page that generates its own code: A guide

If you have created a demo page for your product and want to include a button at the bottom that, when clicked, displays the source code of the demo above, how can you accomplish this in an elegant way? ...

Is that possible to prevent the use of the & symbol in Angular 4 HTTP requests?

Using an HTTP request to save data in my database. The code snippet I used is: const form = '&inputdata=' + myinput + '&rf_date=' + rf_date; return this.http.post(this.rootUrl, form, {headers : this.reqHeader}); In thi ...

Please explain the display property used in Bootstrap input groups

I have been working on implementing a button that toggles the visibility of a datepicker when clicked. <a class="btn btn-primary btn-lg mr-5" href="../Stores/stalls.html">Check Current Operating Stalls </a> <div style="vertical-align: t ...

Capture and reroute the loading of stylesheets, images, and fonts coming from Gecko

Seeking guidance for a C# application utilizing geckofx. I am looking to intercept and redirect the loading of images, fonts, and style sheets. My goal is to potentially load these resources from a database. I've experimented with SetParentURIContentL ...

Using React.js to create table cells with varying background colors

For my React application, I am working with a table that utilizes semantic ui. My goal is to modify the bgcolor based on a condition. In most cases, examples demonstrate something like bgcolor={(condition)?'red':'blue'}. However, I requ ...

determine the selection based on its numerical index

I'm looking to leverage the robot framework for automating user actions involving hovering over a bar chart. Is there a method to identify the bar chart by its index? Or what would be the appropriate selector for using the robot framework to hover o ...

Minimize or conceal iframe

This iframe contains a Google form that cannot be edited. I am looking for a way to close or hide this iframe, either through a button, a popup window button, or without any button at all. The $gLink variable holds the Google form link through a PHP sessio ...

Comparing the Absolute anchor tag to the anchor tag with an absolute span

I have come across two methods for extending a link over a card, container, div, or any other element in order to make the entire area clickable. The first approach involves positioning the <a> tag as an absolute element. The second method keeps th ...

Searching for columns should be at the top of an angular datatable, not at the bottom

In my Angular 7 project, I am utilizing the library found at this link. I have followed the example provided, which can be seen here. Everything is working perfectly, except for the position of the search columns. I would like the search columns to appear ...

Is it possible to incorporate a <div> element within a PHP code?

After successfully writing some PHP/SQL code, I encountered an issue when trying to create a new div called "content" along with applying a CSS class. The recommended approach was suggested as follows: $mydiv = '<div name="content">'; $myn ...

"Ensure div remains at the bottom of the page even while

In order to implement a feature where the menu sticks to the top when scrolling down, you can use the following JS code. You can view a live example of this functionality on this Plunker by widening the preview window to see the columns side by side. wi ...

Trouble with jQuery addClass function when trying to add to a specific object variable

I'm attempting to give an error class to an input textbox to inform the user that their input is invalid. Within the change event, I am referencing what seems to be the input field and storing it in a variable. However, calling addClass on the var ...

JavaScript exit page trigger

I have successfully implemented a way to exit the page with a confirmation using window.onbeforeunload. However, I am curious about how I can customize the appearance of the exit confirmation box by adding CSS and HTML elements, instead of just displayin ...

What is the reason for needing to multiply all the numbers by ten in order to solve this floating point addition problem?

When dealing with floating point arithmetic in Javascript, it's common to see results like 0.2 + 0.1 = 0.30000000000000004, which can be confusing. However, a simple workaround is to multiply the numbers by 10, perform the operation, and then divide b ...

What method can be employed to eliminate choice selection lacking any value?

Currently, I am encountering difficulties in my attempt to remove or hide the first option value from a ransack code. Would you be able to assist me in addressing this concern? Here is the HTML CODE that I am working with: <select id="q_c_0_a_0_name" ...

VueJS encountered an issue while displaying the image

I am facing an issue with VueJS while trying to populate my index.html with images fetched from the iTunes API. The API returns a URL to an image, but I am struggling to render them on my webpage. The 'item' variable holds the object data. Initi ...