Tips for organizing inputs neatly within a fieldset

Why are my text input fields longer than select tags? How can I make inputs have the same width as selects?

form fieldset {
    width: 50%;
    margin: auto;
    border: 3px solid grey;
    padding: 10px;
}
form fieldset legend {
    font-size: 20px;
    font-weight: bold;
}
form label {
    font-weight: bold;
    font-size: 16px;
    margin-top: 10px;
}
form input, select {
    margin-bottom: 10px;
    padding: 5px;
    border: 0;
    border-bottom: 1px solid grey;
    font-size: 16px;
    width: 100%;
    font-family: 'Poppins';
}
form input[type=submit] {
    font-size: 20px;
    border: 0;
    font-weight: bold;
    margin-top: 10px;
}
form input:focus, select:focus {
    outline: none;
    border-bottom: 2px solid black;
}
form div.submit {
    width: 20%;
    margin-left: auto;
    margin-right: auto;
}
<!DOCTYPE html>
<html lang='cs'>
  <head>
      <meta charset='UTF-8'>
      <title>Title</title>
  </head>
  <body>
    <form method='POST' action='quotation.php?a=insert'>
      <fieldset>
        <legend>My legend</legend>
        <label for='customer'>Customer: </label><br>
        <select name='customer' id='customer'>
          <option value='NULL'></option>
          <option value='1'>Cust. 1</option>
          <option value='2'>Cust. 2</option>
          <option value='3'>Cust. 3</option>
        </select><br>
        <label for='contact_person'>Contact person: </label><br>
        <select name='contact_person' id='contact_person'>
          <option value='NULL'></option>
          <option value='1'>CP 1</option>
          <option value='2'>CP 2</option>
          <option value='3'>CP 3</option>
        </select><br>
        <label for='project'>Project: </label><br>
        <input type='text' name='project' id='project'><br>
        <label for='part'>Part: </label><br>
        <input type='text' name='part' id='part'><br>
        <label for='recieved'>Recieved: </label><br>
        <input type='date' name='recieved' id='recieved'><br>
        <label for='deadline'>Deadline: </label><br>
        <input type='date' name='deadline' id='deadline'><br>
        <div class='submit'>
          <input type='submit' value='Save'>
        </div>
      </fieldset>
    </form>
  </body>
</html>

Thank you for any ideas.

I attempted to set padding of the entire fieldset:

fieldset { padding: 5px }

This worked with the <p> tag but not with <input>. So, I tried setting: input {margin: 5px} but it didn't work either. In Chrome DevTools, I noticed that the margin was outside of the fieldset area.

Answer №1

When setting padding on a box, it can cause the border to extend beyond the boundaries of the box. To prevent this, set the top and bottom padding to 5px, while keeping the right and left padding at 0.

form input, select {
 margin-bottom: 10px;
 padding: 5px 0;
 border: 0;
 border-bottom: 1px solid grey;
 font-size: 16px;
 width: 100%;
 font-family: 'Poppins';
}

Answer №2

Simple tweak to the CSS.

form input, select{
padding: 5px 0;}

Answer №3

After including the following CSS:

form input, select {
  box-sizing: border-box;
}

The problem I was facing got solved.

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

Using jQuery's sortable functionality to rearrange rows in a table can cause conflicts with Angular's orderBy feature

In the past, my angular app used a table with orderBy to sort rows based on a specific column. By clicking on a table header, the orderBy arguments would change and the list would be sorted according to the values in that column. Now, I am experimenting w ...

Mistakes found in the 'com/badlogic/gdx/backends/gwt/GwtApplication.java file while working on an HTML 5 project

Just recently, I discovered the amazing framework known as Libgdx. As a newcomer to this framework, I am encountering a few challenges. After cloning the entire repository and running the gdx-setup-ui.jar file, I obtained 4 basic starter projects (my-gdx-g ...

Styling a jQuery Chosen Select Box: Tips and Tricks

I am currently utilizing jQuery chosen plugin for my multi-select box. However, I am facing some challenges with customizing the styles defined in the chosen.css file as they are proving to be quite stubborn to override. Removing the entire chosen.css file ...

JavaScript multiplying an array in HTML

Snippet of HTML code <input name="productCode[]" value="" class="tInput" id="productCode" tabindex="1"/> </td> <input name="productDesc[]" value="" class="tInput" id="productDesc" readonly="readonly" /></td> <input name="pr ...

Tips on replacing views within ion-view and updating the title in the title bar to match the injected page through the use of Ionic and AngularJS

I am new to ionic and angular JS. I am currently working on a simple app within the ionic framework. My goal is to inject an HTML template into the ion-view tag using ngRoute. However, I am facing issues as my code is not successfully injecting the HTML te ...

What is the trick to incorporating nested tabs within tabs?

My tabs are functional and working smoothly. To view the jsfiddle, click here - http://jsfiddle.net/K3WVG/ I am looking for a way to add nested tabs within the existing tabs. I would prefer a CSS/HTML solution, but a JavaScript/jQuery method is also acce ...

Column spacing and size manipulation with Bootstrap 4

I'm currently facing an issue with aligning elements and spacing them correctly in my project. How can I resolve this using only the col class and Bootstrap 4, without resorting to CSS? I have attempted various margin spacing options like ml-md-4 and ...

"Discover the art of arranging div elements into a grid format with multiple rows and two columns

<div class="parent"> <div class="col">1</div> <div class="col">2</div> <div class="col">3</div> <div class="col">4</div> <div class="col">5</div> <div class="col">6</div ...

Constructing an HTML form that includes radio buttons and integrating PHP for processing the

I have created an HTML form with radio buttons and I am wondering how to determine which button has been selected. I want to send the selected option to my email address, but I'm not sure how to integrate this into my PHP script. Thank you for any hel ...

unexpected alteration of text sizing in mathjax within reveal.js presentations

Something strange is happening with the font size in my slides. The code for each slide is the same, but there is an unexpected change between the 3rd and 4th slide. I cannot figure out what is causing this discrepancy. Oddly enough, when I remove the tit ...

Tips for adjusting text to perfectly fit within a DIV's width

I'm facing an issue where the contents in my DIV are not wrapping correctly when the width changes. Specifically, whenever the content includes a long string of characters like "______________________________________________________________" with no s ...

challenges with positioning div elements using relative CSS styling

This is a section of my code: CSS : .body .left, .right { position:relative; z-index:6; display:inline-block; } .body .left { top:0; left:0; width:100px; height:300px; margin-right:10px; borde ...

The integration of jquery datepicker with MVC in Visual Studio 2013 allows for seamless

I recently started developing an application in Visual Studio 2013 using MVC. I am currently working on implementing a jquery datepicker to show up whenever there is a DateTime field involved. My controllers are being created through scaffolding templates. ...

PHP's Encoding Woes Are Back in Action

I'm encountering encoding challenges on my website, and it's becoming quite frustrating. Allow me to elaborate My meta tag specifies utf8 as the charset. The scripts I'm using also have utf8 defined (<script type="text/javascript src=". ...

Is it possible to deactivate or replace flexslider using media queries?

In the process of developing a landing page, I encountered a challenge with displaying testimonials. On the desktop version, the 3 testimonials are arranged in 3 columns. However, for mobile and smaller screens, I needed to showcase them in a slideshow for ...

Struggling with a non-functional jQuery navigation tab onclick feature

Within my Django template, I am working with a series of nav-tabs that are being populated by a context variable: <div class="content-object"> <ul class="nav nav-tabs nav-fill" id="object_tab" role="tablist"> {% for object in object_ ...

Steps for placing a figcaption above an image

Does anyone know how to position a figcaption at the bottom of an img so that it appears on top of the image with a transparent background? I've been having trouble making them the same width and getting the figcaption to sit on top of the image. Whe ...

Is there a way to smoothly incorporate a new animation into a page, while ensuring that existing elements adjust to make room for it?

I am looking to smoothly fade and move a hidden element (display:none) within the page, shifting other elements to animate into their new positions as necessary. When I reveal the hidden element by changing it to "display:initial," it should seamlessly a ...

Switch the color of the final letter

Sample code snippet: <p class="test">string</p> Looking to dynamically change the color of the last letter, specifically the letter "g", using CSS only, without relying on JavaScript. I am displaying the string character by character and nee ...

The header does not appear to be responding to CSS floats

I am currently designing a header that includes a brand logo and a navigation menu. The header is nested within a div called container, and the HTML markup looks like this - <div class="container"> <div class="head"> ...