Ways to minimize excessive gap between two columns in Bootstrap

How can I reduce the space between two form-groups without moving the email address field with CSS left margins? When I try to make the first column smaller, it automatically wraps to the next line, but I want the email address to be closer to the phone extension. Is there a way to achieve this?

    <div class="row">
        <div class="form-group col-md-5">
            <label for="telephoneNumber">Telephone Number</label>
            <div class="form-inline">
                <input type="text" class="form-control" id="telephoneNumber1" maxlength="3" size="3">-
                <input type="text" class="form-control" id="telephoneNumber2" maxlength="3" size="3">-
                <input type="text" class="form-control" id="telephoneNumber3" maxlength="3" size="3">Ext
                <input type="text" class="form-control" id="extension" maxlength="3" size="3">

            </div>
        </div>
        <div class="form-group col-md-4">
            <label for="emailAddress">Email Address</label>
            <input type="text" class="form-control" id="emailAddress">
        </div>
    </div>

Answer №1

The total number of columns in a row is always 12.

By assigning the class .col-md-5 to your first column, you are using up half of the available width right away. This can cause alignment issues if your next column starts immediately after that. One solution is to use a class with fewer columns for your first form-group, such as col-md-3. Here's an example:

Answer №2

<!-- HTML -->
<div class="row">
    <div class="form-group col-md-12">
      <div class="inline-block">
          <label for="phoneNumber">Phone Number</label>
              <div class="form-inline">
                <input type="text" class="form-control" id="phoneNumber1" maxlength="3" size="3">-
                <input type="text" class="form-control" id="phoneNumber2" maxlength="3" size="3">-
                <input type="text" class="form-control" id="phoneNumber3" maxlength="3" size="3">Ext
                <input type="text" class="form-control" id="extensionNumber" maxlength="3" size="3">
              </div>
      </div>
      <div class="inline-block">
          <label for="userEmail">User Email</label>
          <input type="text" class="form-control" id="userEmail">
      </div>
    </div>
</div>

<!-- CSS-->
.inline-block {display: inline-block;}

Answer №3

<div class="row">
    <div class="form-group col-md-5 no-padding">
        <label for="telephoneNumber">Telephone Number</label>
        <div class="form-inline">
            <input type="text" class="form-control" id="telephoneNumber1" maxlength="3" size="3">-
            <input type="text" class="form-control" id="telephoneNumber2" maxlength="3" size="3">-
            <input type="text" class="form-control" id="telephoneNumber3" maxlength="3" size="3">Ext
            <input type="text" class="form-control" id="extension" maxlength="3" size="3">

        </div>
    </div>
    <div class="form-group col-md-4 no-padding">
        <label for="emailAddress">Email Address</label>
        <input type="text" class="form-control" id="emailAddress">
    </div>
</div>

Apply the following CSS classes:

.less-padding {
   padding: 10px !important;
   margin: 10px !important;
}
.no-padding {
   padding: 0 !important;
   margin: 0 !important;
}

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

AngularJS: dynamic autocomplete field with scroll functionality

This is my HTML code: <div class="form-group"> <label class='control-label col-md-4' for='id_paymentCurrency'>{{'PAYMENT_CURRENCY' | translate}}</label> <div class='col-md-4'> ...

Open the link and input the text into the text box?

Suppose I have the following JavaScript code: <script language="javascript" type="text/javascript"> function addText() { var newText = document.myForm.inputText.value; document.myForm.description.value += newText; } </script> I want t ...

What is the process for customizing the image size of a WordPress RSS feed in pixels?

Is there a way to customize image sizes beyond the 'thumbnail', 'medium', and 'large' options? I tried setting width and height in the <img> tag within an RSS file, but it didn't work. Could it be a nested quotation ...

Spacious width that doesn't require a horizontal scrollbar for navigation

My dilemma is with the width of my body and background image. I set the body width to 1920px to match the background-image for the header. However, since I have a narrower wrapper inside the body, the header background's width gets cut off by the wrap ...

Altering the dimensions of radio buttons

I am a newcomer to using material-ui. I am currently working on incorporating radio buttons in a component and would like to reduce its size. While inspecting it in Chrome, I was able to adjust the width of the svg icon (1em). However, I am unsure how to a ...

What is the process of invoking a Java method through AJAX on a website?

I am trying to figure out how to call the Java method getMessage() from a jar file whenever a button on my webpage is clicked. Can anyone help me achieve this? File name: index.html <!doctype html> <html> <head> <meta charset="utf-8" ...

Strange border adjustment for customized-height input[type=button] in Internet Explorer 6 and Firefox 3

Upon my discovery, I encountered a peculiar issue in IE6/FF3 when trying to set a custom height (even if it matches the default) on a button. The following code illustrates that although both buttons have the same height, their padding differs inexplicably ...

Using Python with Selenium, attempt to click on a button designated as type="button"

I've been trying to click on a button in this Airbnb listing but none of the codes I tried seem to work. Here is one example of the HTML code: <li data-id="page-2" class="_1eqazlr"> <button type="button" class="_1ip5u88" aria-label="Page 2 ...

The paragraph tag remains unchanged

I am currently working on developing a feature that saves high scores using local storage. The project I'm working on is a quiz application which displays the top 5 scores at the end, regardless of whether the quiz was completed or not. However, I&apo ...

Manipulate the lines in an HTML map and showcase the distinctions between them

I've been searching through various inquiries on this particular subject, but none have provided me with a satisfactory response. I have created a map where I've set up 4 axes using the following code: function axis() { var bounds = ...

Using div elements to mimic the layout of tables with row spans

<div class="container"> <div class="box1">1</div> <div class="box2">2</div> <div class="box3">3</div> </div> .box1 { border: 1px solid red; float: left; width: 20px; } .box2, .box3 { ...

Showcasing articles in an XML feed according to specific keywords found in the headline

I'm currently working on designing a website for a client and I want to minimize my involvement in its maintenance. I am considering using RSS feeds to automate the process by having content posted on Blogger and then feeding it to the site. However, ...

What is the process to change the URL?

Currently, I am deep into developing a large-scale web application for a company. The project has been ongoing for about four months now, and we have encountered a harmless yet annoying issue that we haven't had time to address. The problem lies in t ...

Hold off on showing the image until it has finished loading

// Here's the code snippet angular .module('imgapp', []) .controller('mainCtrl', mainCtrl); function mainCtrl() { var vm = this; vm.first = { title: 'Image 1', url: 'http://www.image-mapper.com ...

positioning a picture at the middle of a link

Struggling to horizontally center an image within an anchor tag? Despite trying various methods like setting it as a block element, applying auto margins, and nesting divs, the image stubbornly remains aligned to the left. Even after looking at other resou ...

Step-by-step guide to implementing a sticky header while scrolling

How can I implement a fixed header on scroll, like the one seen on this website: www.avauntmagazine.com Here is the HTML for my header: <div class="bloc bgc-wild-blue-yonder l-bloc " id="bloc-1"> <div class="container bloc-sm"> &l ...

CSS - selecting elements that are greater than a specific criteria N

I have multiple <p> tags in the body of my HTML. I want to display only the first two paragraphs and hide all the paragraphs that come after. However, the code I'm using doesn't seem to work as expected. <html> <head> < ...

How to control the audio currentTime using Angular 2 component

Here is the HTML code snippet that creates an HTML5 audio element: <audio id ="audio2" controls="controls" autoplay="false" (canplay)="CanPlay($event)"> <source src="http://localhost:51657/Audio/1" type="audio/mp3"> </audio> In the ...

Discovering the potential of HTML5 Canvas matrix transformations

Throughout various Html5 resources, authors frequently discuss: transform(1,0,0,1,0,0) being equivalent to transform(0,1,1,0,0,0). I find this confusing. From my perspective, that implies newX = oldX/newY = oldY is the same as newX = oldY/newY = oldX. ...