Decreasing the gap between form controls such as textboxes and labels with Bootstrap

I am currently working on a .NET (C#) MVC web application and I have implemented a Bootstrap dropdown menu in my project.

My main objectives are as follows:

  • 1) I aim to minimize the space between a label and its corresponding text-box. Initially, I attempted using "col-xs-1 col-form-label" instead of "col-xs-2 col-form-label", but this caused the textbox to overlap with the label.

  • 2) I also want to decrease the height of the textbox.

How can I go about achieving these goals?

Below is an excerpt from my cshtml code :

<div class="container">
<div class="row">

    <div class="input-group" id="adv-search">
        <input type="text" class="form-control" placeholder="Search" id="searchBar" />

        <div class="input-group-btn">

            <div class="btn-group" role="group">

                <button type="button" class="btn btn-primary" onclick="ReloadData()"><span class="glyphicon glyphicon-search" aria-hidden="true" onclick="ReloadData()"></span></button>

                <div class="dropdown dropdown-lg">
                    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false" title="Click To Expand"></button>

                    <div class="dropdown-menu dropdown-menu-right" role="menu">
                        <form class="form-horizontal" role="form" style="font-family:Calibri;font:94% 'v', sans-sarif;background-color:#FAFAFA">
                            <br />

                            <div class="form-group row">
                                <label for="RequestNo" class="col-xs-2 col-form-label">Request No.</label>
                                <div class="col-md-2">
                                    <input class="form-control" type="text" id="txtChopRequestNo" onKeyDown="if (event.keyCode == 13) ReloadData()" />
                                </div>

                                <label for="ReferenceNo" class="col-xs-2 col-form-label">Reference No.</label>
                                <div class="col-md-2">
                                    <input class="form-control" type="text" id="txtReferenceNo" onKeyDown="if (event.keyCode == 13) ReloadData()" />
                                </div>

                                <label for="RequestNo" class="col-xs-2 col-form-label">Request No.</label>
                                <div class="col-md-2">
                                    <input class="form-control" type="text" id="txtCreatedBy" />
                                    @*@Html.TextBox("name",null, new { id = "txtCreatedBy", style = "width:156px;" })*@                             
                                </div>
                            </div>

                            <div class="form-group row">
                                <label for="RequestNo" class="col-xs-2 col-form-label">Request No.</label>
                                <div class="col-md-2">
                                    <input class="form-control" type="text" id="txtChopper" onKeyDown="if (event.keyCode == 13) ReloadData()" />
                                </div>

                                <label for="RequestNo" class="col-xs-2 col-form-label">Request No.</label>
                                <div class="col-md-2">
                                    <input class="form-control" type="text" id="txtManager" onKeyDown="if (event.keyCode == 13) ReloadData()" />
                                </div>

                                <label for="RequestNo" class="col-xs-2 col-form-label">Request No.</label>
                                <div class="col-md-2">
                                    <input class="form-control" type="text" id="txtLeagalApprover" onKeyDown="if (event.keyCode == 13) ReloadData()" />
                                </div>
                            </div>

                           //and so on

                        </form>
                    </div>
                </div>
                <button type="reset" class="btn btn-warning" id="clearAll" style="background-color:#cc0000" data-toggle="tooltip" title="Clear All Search Parameters">
                    <span class="glyphicon glyphicon-remove"></span>
                </button>
            </div>
        </div>
    </div>
</div>

Furthermore, here's a snippet from my CSS code :

.dropdown.dropdown-lg .dropdown-menu {
    margin-top: -1px;
    padding: 6px 20px;
}
.input-group-btn .btn-group {
    display: flex !important;
}
.btn-group .btn {
    border-radius: 0;
    margin-left: -1px;
}
.btn-group .btn:last-child {
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
}
.btn-group .form-horizontal .btn[type="submit"] {
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
}
.form-horizontal .form-group {
    margin-left: 0;
    margin-right: 0;
}
.form-group .form-control:last-child {
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
}

@media screen and (min-width: 1000px) {
    #adv-search {
        width: 1110px;
        margin: 0 auto;
    }
    .dropdown.dropdown-lg {
        position: static !important;
    }
    .dropdown.dropdown-lg .dropdown-menu {
        min-width: 1110px;
    }
}

Answer №1

I am on a mission to decrease the space between a label and its corresponding text box.

To achieve this, assign a custom CSS class (such as pull-left) to your text boxes and then use CSS to shift them towards the left side.

.pull-left { margin-left: -20px; /* Experiment with different values until you are satisfied */ }

I am seeking to minimize the height of the text box.

You can try adjusting the height using padding and line-height, playing around with the measurements until you find the right height:

input[type="text"]{ padding: 20px 10px; line-height: 28px; }

The provided code will add 20px to the top and bottom, and 10px to the left and right. Here are other alternatives:

padding: 20px 10px 20px 10px; /*top right bottom left*/ 

Remember to ensure that these adjustments look good across varying screen sizes. What appears ideal on a large screen may not translate well on smaller screens, so opt for a design that is universally appealing.

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

How can I add text to the title of a border using Bootstrap5?

I am attempting to create a design where text appears within the border of an element. I am currently utilizing Bootstrap 5 and jQuery for this project. Despite my efforts with fieldset and legend elements, I have not been successful in achieving the desir ...

Processing of an array received via AJAX and passed to a PHP script, inside a separate function in a different file

I have a JavaScript array that I am sending via AJAX to a PHP file named aux.php. What I want is for this array to be visible and manipulable within a function inside a class in another PHP file called payments.php. I've provided all the code so they ...

Looking to display an input field when a different option is chosen from the dropdown menu?

I'm currently utilizing ng-if to toggle the visibility of an input box. However, whenever I refresh the page, the input box automatically appears and then hides after selecting an option. Below is my code snippet. Any suggestions would be greatly appr ...

What is the best way to access the current element in a loop function?

I'm facing an issue with a nested each function and I need help on how to refer to the current item when the if statement is triggered: // checking for empty array if(sameValArr.length === 0) { $(this).hide(); // hiding the current video thumbnail ...

What might be causing the navigation to malfunction in Firefox?

Could you please help me identify the issue with the navigation on this website? It seems to work correctly on webkit, but not on firefox! Intended vs actual ...

Analyzing the results of the Azure BatchClient Transcription process

A new application has been developed to efficiently run the batch transcription service on Azure. The response is in JSON format and needs to be deserialized into an object. The object structure, which was extracted from a Microsoft sample code without any ...

What are two ways to tell them apart?

<?php if($_SERVER["REQUEST_METHOD"] == "POST") { } ?> <form action = "" method = "post"> <label>Name of vegetable</label><br> <input type = "text" name = "vegetable" class = "box" placeholder="Enter Ve ...

What steps can be taken to customize the default keyboard shortcuts functionality in Swiper.js?

I am trying to customize the functionality for left/right keys in Swiper.js but I am unable to find a way to do this through the API () It seems that the API only allows you to disable/enable default actions: mySwiper.keyboard.enabled // Whether th ...

Obtain a specific portion of text from a string that resembles a URL

$("#index-link")[0].search = "?isNameChecked=False&isDateChecked=False&isStatusChecked=True" Is there a way to use jQuery to identify whether isStatusChecked is set to true or false in the given string? ...

Delete a particular instance of a component from an array within the parent component when a button is clicked within the child component, depending on a specific condition in Angular

One scenario I am facing involves the removal of a component instance from an array (located in the parent component) when a button is clicked inside the child component, based on a specific condition. https://i.sstatic.net/YPFHx.png Within the parent co ...

Angular does not allow the transfer of property values from one to another

As of late, I have delved into learning Angular but encountered an issue today. I have the following Component: import { Component, OnInit } from '@angular/core'; import { SharedService } from '../home/shared.service'; import { IData } ...

How can I restrict unauthorized users from accessing a protected web page in ASP.NET web forms using Okta?

I am currently attempting to integrate Okta into an aging ASP.Net Web Forms application. Following the guidance from this demo: , I have implemented the necessary changes in my solution. My next objective is to secure specific web pages, allowing only au ...

Looping Issue in WordPress

Here is the code snippet I am currently working with: <?php query_posts("order=ASC&cat=4"); ?> <?php if(have_posts()): while(have_posts()): the_post(); ?> <?php if(get_post_custom_values("show") != NULL): ?> ...

How to activate Vue Devtools for debugging in Laravel 5.4

I'm looking to incorporate Vue into my laravel 5.4 application. When I use Vue without laravel, I can see the vue devtools inspection tab in Chrome. However, within my laravel app, the Vue tab is not visible in the Chrome console even though the chrom ...

Python Selenium: Troubleshooting the get_elements method not retrieving li items within ul tags

I am facing an issue while trying to retrieve li items within a ul element using the following code: driver.get('https://migroskurumsal.com/magazalarimiz/') try: select = WebDriverWait(driver, 10).until( EC.presence_of_element_locate ...

`Javascript framework suggests ajax navigation as the preferred method`

What is the best way to handle ajax navigation using jQuery? I have recently experimented with a simple jQuery ajax code to implement ajax-based navigation for all the links on a webpage. $('a').click(function(e){ e.preventDefault(); ...

Assign a pair of CSS classes that each include the `filter` property to an HTML element

Is there a way to apply both aaa and bbb classes to an element simultaneously? I tried using class="aaa bbb" but it didn't work as expected. Any suggestions on how to achieve this? <html> <head> <style> .aaa ...

Foundational 5 Grid Shuffle Shift

I am currently utilizing Foundation 5 and am aiming to create a unique DIV layout on a mobile display: -------------------- | A | -------------------- | B | -------------------- | C | -------------------- | ...

Creating Angular UI states with parameters in TypeScript

My Understanding In my experience with TypeScript and angular's ui state, I have utilized "type assertion" through the UI-Router definitely typed library. By injecting $state into my code as shown below: function myCtrl($state: ng.ui.IStateService){ ...

WordPress taxonomy.php Issue: not Displaying

I've successfully created a Custom Post Type and custom taxonomy. However, when I attempt to view any category, the page defaults to index.php instead of taxonomy.php. Even after trying taxonomy-portfolio-category.php, it still redirects to index.php. ...