Ways to minimize the spacing between labels and input fields

I have a Bootstrap Form with labels and input fields. I am looking for a way to reduce the space between the label and the input field. Please see the code and screenshot below for reference.

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">

<div class="form-group row">
  <label class="col-sm-1 col-form-label col-form-label-sm">First Name</label>
  <div class="col-sm-3">
    <input type="text" name="FirstName" class="form-control form-control-sm" id="TxtFirstName" placeholder="First Name" value={this.state.FirstName} required onChange={this.onChangeHandler}/>
  </div>

  <label class="col-sm-1 col-form-label col-form-label-sm">Last Name</label>
  <div class="col-sm-3">
    <input type="text" name="LastName" class="form-control form-control-sm" id="TxtLastName" placeholder="Last Name" value={this.state.LastName} required onChange={this.onChangeHandler}/>
  </div>

  <label class="col-sm-1 col-form-label col-form-label-sm">Email Id</label>
  <div class="col-sm-3">
    <input type="email" name="EmailId" class="form-control form-control-sm" id="TxtEmailId" placeholder="EmailId" value={this.state.EmailId} required onChange={this.onChangeHandler}/>
  </div>
</div>

screenshot:-

https://i.sstatic.net/9h763.jpg

Answer №1

If you want to adjust the spacing in your form, consider adding the pl-0 class to the input parent element. To further decrease the gap, you can safely reduce the max-width attribute of the label tag.

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">

<div class="form-group row">
  <label class="col-sm-1 col-form-label col-form-label-sm">First Name</label>
  <div class="col-sm-3 pl-0">
    <input type="text" name="FirstName" class="form-control form-control-sm" id="TxtFirstName" placeholder="First Name" value={this.state.FirstName} required onChange={this.onChangeHandler}/>
  </div>

  <label class="col-sm-1 col-form-label col-form-label-sm">Last Name</label>
  <div class="col-sm-3 pl-0">
    <input type="text" name="LastName" class="form-control form-control-sm" id="TxtLastName" placeholder="Last Name" value={this.state.LastName} required onChange={this.onChangeHandler}/>
  </div>

  <label class="col-sm-1 col-form-label col-form-label-sm">Email Id</label>
  <div class="col-sm-3 pl-0">
    <input type="email" name="EmailId" class="form-control form-control-sm" id="TxtEmailId" placeholder="EmailId" value={this.state.EmailId} required onChange={this.onChangeHandler}/>
  </div>
</div>

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

Toggle jQuery slide effect showing all elements and not hiding other list items

I'm utilizing this to display a sub list: function showSublist(element) { $(element).find('ul.joinus_subtext').slideToggle(); } and below is the HTML markup: <ul class="joinus"> <li onclick="showSublis ...

Is there a way to dynamically alter the content depending on the index of the current slide using swiper.js?

Hi, I am new to utilizing the Swiper framework and so far, it has been one of the best sliders I have ever experienced. Currently, I am trying to establish a connection between 2 div tags - one tag holds the content of each slide while the other tag contro ...

Unable to set two image layers on HTML canvas to display in different colors as anticipated

I am facing a challenge with stacking 3 images: an outline, a white base, and a pattern that is also white. My goal is to layer these images where the base is at the bottom with one color assigned to it, the pattern is stacked on top with a different color ...

What is the best way to extract the name from JSON data?

I have a list of items in my HTML with data attributes. When a user clicks on one of the items, I want to display or append a list of related suburbs for that selected item in another list. This is being achieved using ajax. <ul id="cities"> <l ...

Is Flash now irrelevant? What makes HTML5 or CSS3 so powerful?

While I may not consider myself a dedicated Flash Activist, it's hard to ignore the fact that despite its flaws, there are some important uses for it on certain websites. However, with all the buzz around HTML5 and CSS3 being the future of the web, ev ...

How to send PHP email using HTML form

After attempting to find an answer to my inquiry here, I am now starting a new thread. Just a brief explanation: I have a Contact Form with 180 input fields and calculations for each field. I wish to send all the fields along with the calculated values v ...

Stop jQuery from resetting the background image when using fadeOut()

Currently, I am using fadeIn and fadeOut functions with jQuery to create a fading effect. However, when the final fade out occurs, the entire CSS table fades out and the background image of the CSS body comes into view. Despite setting the background-posit ...

Integrating md-chips md-separator-keys with md-autocomplete: A step-by-step guide

My experience with using md-chips and md-autocomplete reveals an issue: when I incorporate md-separator-keys, it functions as expected. However, upon adding md-autocomplete, the md-separator-keys functionality ceases to work. This is how my code is struct ...

Adapt the table width to fit different screen resolutions

Is there a way to adjust the width of a table to fit the screen, regardless of changes in screen resolution? For example, , where the black header always adjusts to the screen size. ...

Creating a vertical line at the bottom using CSS

Is it possible to add a centered line to the bottom of the "numberCircle" in a responsive table created with twitter-bootstrap? I would like it to look like this image: https://i.sstatic.net/WKgFu.jpg Thank you .numberCircle { border-radius: 50%; ...

jQuery not functioning properly when attempting to add values from two input boxes within multiple input fields

I am facing an issue with a form on my website that contains input fields as shown below. I am trying to add two input boxes to calculate the values of the third input box, but it is only working correctly for the first set and not for the rest. How can ...

Dynamic text formatting tool with mathematical equations support, media recording/uploading capabilities, and an innovative drawing feature

Seeking a robust text editor with the ability to handle math equations, record/upload media, and include a drawing tool for integration into my website. Are there any internet tools available (free or commercial) that offer these features? I have come ac ...

Stop the page from automatically scrolling to the top when the background changes

Recently, I've been experimenting with multiple div layers that have background images. I figured out a way to change the background image using the following code snippet: $("#button").click(function() { $('#div1').css("background-image ...

Unknown identifier in the onClick function

I want to create a JavaScript function that can show or hide a paragraph when clicking on an arrow. The challenge I'm facing is that I have a list of titles generated in a loop on the server, and each title is accompanied by an arrow. Initially, the c ...

Is there an event handler for clicking on the search field icon in HTML5

My html5 search field includes <input type='search'>, and I have a jQuery event set up to sort items as the user types. However, when the user presses the small X icon that appears on the right side of the input field to clear it, the jQuer ...

When a DIV is clicked, trigger the fadein effect on another DIV; when the same DIV is clicked again, fade

I have a sliding panel on my webpage that reveals the navigation (www.helloarchie.blue). I want the content inside the panel to fade in slowly when it slides out, and then fade out when the user clicks the icon to close the panel. How can I achieve this ef ...

What is the best way to display the output after retrieving an array?

Database : --> product table P_id P_name P_uploadKey 1 Cemera 7365 2 Notebook 7222 3 Monitor 7355 4 Printer 7242 --> buy table B_id P_id B_nam ...

Retrieving inner text using HTML Agility Pack

I need assistance with parsing a website I have found here: https://i.sstatic.net/GdFN1.png My goal is to extract information from specific fields that have IDs and classnames: label = node.SelectSingleNode( ".//h3[@c ...

Instructions for including user ID in the URL after successfully logging in with their information

Hello everyone, I have a question and I would appreciate some help. I am attempting to ensure that when a user logs in with their credentials, their ID is passed and visible in the URL bar like this: ?id=000. I have been trying various ways but have not b ...

ways to animate the closing of a dropdown menu

I'm currently working on a navbar dropdown animation code that works on hover. However, I've encountered an issue when trying to use it on a phone - I can open the dropdown, but I can't seem to close it. Does anyone have suggestions on how ...