Creating consistent widths for drop downs and text boxes in Bootstrap

I'm currently using VB.Net MVC, Razor, Bootstrap, and Visual Studio 2013. My clients have requested that the dropdowns match the width of the text boxes.

Here is how I create my dropdowns:

@<div class="row">
    <div class="col-md-4">
        <label>@Model.ListOfFields(i): </label>
    </div>
    <div class="col-md-8">
        <div class="btn-group">
                <button class="btn btn-default dropdown-toggle btn-sm" type="button" 
                              id="@Model.ListOfFields(i)" data-toggle="dropdown" 
                              aria-expanded="true">

                     <span class="search" id="@Model.ListOfCategoryAttributeIDs(i)" ></span>
                     <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu" role="menu" aria-labeledby="@Model.ListOfFields(i)">

                    @For x As Integer = 0 To Model.ListOfDropDowns.Count - 1
                    Dim currentField As String = Model.ListOfFields(i)
                    Dim currentObject As CivilServiceInventoryMock.ViewModels.customDropDown = Model.ListOfDropDowns(x)

                    If (currentObject.fieldType).Equals(currentField) Then

                        Dim currentOption As String = currentObject.dropDownValue

                            @<li role="presentation">
                                <a id="ddListSelectItemType" class="ddListSelectItemType"
                                      onclick="lockValue(this)" role="menuitem" 
                                      tabindex="-1">
                                   <div class="itemOptions" id="@Model.ListOfCategoryAttributeIDs(i)">
                                       @Html.DisplayFor(Function(modelItem) currentOption)
                                   </div>
                                 </a>
                             </li>
                         End If
                         Next
                     </ul>
                </div>
           </div>
      </div>

This is how I create a text box:

    @For i As Integer = 0 To Model.ListOfDisplayTypes.Count - 1
        If Model.ListOfDisplayTypes(i).Equals("TextBox") Then
        @<div class="row">
            <div class="col-md-4">
                <b>@Model.ListOfFields(i): </b>
            </div>
            <div class="col-md-4">
                <input class="search" id="@Model.ListOfCategoryAttributeIDs(i)" 
                      name="@Model.ListOfFields(i)" type="text" placeholder="@Model.ListOfFields(i)" />
            </div>
        </div>
        End If
    Next

I've tried different CSS combinations to make the dropdowns and text boxes match in width without success. Could there be a specific combination of column size and width percentage to achieve this?

Answer №1

Take a look at the Boostrap documentation for more information: http://getbootstrap.com/css/#forms

To create an inline form, simply add the class "form-inline" to the parent container that groups the input elements together (it doesn't have to be a form element).

Once you've added the "form-inline" class, make sure to wrap the input elements with `div` tags and they will appear in the same size.

@For j As Integer = 0 To Model.ListOfDisplayTypes.Count - 1
    If Model.ListOfDisplayTypes(j).Equals("TextBox") Then
    @<div class="row">
        <div class="form-group col-md-4">
            <b>@Model.ListOfFields(j): </b>
        </div>
        <div class="form-group col-md-4">
            <input class="search" id="@Model.ListOfCategoryAttributeIDs(j)" 
                  name="@Model.ListOfFields(j)" type="text" placeholder="@Model.ListOfFields(j)" />
        </div>
    </div>
    End If
Next

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

What is the best way to change the maxWidthLg of Material UI's .MuiContainer?

I need to remove the max-width that is set in the theme. When I look at it in Chrome and uncheck the option, it functions as desired: @media (min-width: 1280px) .MuiContainer-maxWidthLg { max-width: 1280px; } How can I achieve this? I have attempted ...

Can you provide a tutorial on creating a unique animation using jQuery and intervals to adjust background position?

I am attempting to create a simple animation by shifting the background position (frames) of the image which serves as the background for my div. Utilizing Jquery, I aim to animate this effect. The background image consists of 6 frames, with the first fr ...

The issue with ng-bind-html causing the disappearance of paragraph spaces

Is there a way to preserve paragraph breaks when using ng-bind-html to display text on the screen? I am having an issue where all the text appears as one big chunk if there are paragraph breaks in the data pulled from the database. Not sure what is causing ...

Having difficulty with PHP code, attempting to output some HTML while also opening a file and displaying its contents

I'm completely new to PHP and I've been experimenting with some code to display button elements that, when pressed, should open a file and write a number to it. Unfortunately, the code doesn't seem to be working as expected and I'm stru ...

Implementing jQuery .load to effectively extract the Title tag from HTML code

I am currently utilizing .load to fetch and load pages, as well as modify their window titles. The page loads successfully; however, the main issue I am facing is my inability to extract the title from the HTML code present in the response. Below is the c ...

Issue with manipulating background color with JQuery in CSS

Currently, I have a simple navigation menu consisting of five links. The navigation bar is styled with a background image and changes to a darker shade when hovered over. My goal is to implement a jQuery script that dynamically changes the color of the act ...

Encountered an error while attempting to load resource in Node.js

I'm currently working on a project utilizing Node js (Express...). Let me do my best to explain the issue I am encountering. My work is being done on localhost, and the main page of my index.html has buttons that lead to other pages when clicked. I c ...

Exploring the versatility of Bootstrap 4's grid system with varying column widths

I am encountering an issue with div alignment in my code. The first two col-3 classes seem to have different widths than the next two col-3 classes, causing elements to appear unaligned. Here is the code snippet: <link href="https://stackpath.bootstr ...

Incorporating local JSON data into HTML: A Step-by-Step

I'm completely new to javascript and the utilization of json. What I want to accomplish is quite straightforward, although I am encountering difficulties. My objective is to create a website consisting of two pages: one that showcases artists and ano ...

Steps for creating a jQuery function that responds to changes in a text box value

Currently, I have a text box containing certain values and a submit button alongside a slider. When I click the submit button, the slider changes. However, I would like to achieve the functionality where instead of clicking the submit button, changing the ...

Enhance Your File Uploads with Custom Images in Bootstrap

For the file upload buttons, I have used the given image by customizing the button look using Bootstrap 3. Here is an example of how I achieved this: <label class="btn btn-primary" for="my-file-selector"> <input id="my-file-selector" type="fi ...

How can I toggle the visibility of a div based on whether a variable is defined or not?

How can I display a specific div on my webpage only when certain variables in PHP pull out a specific result from a database? I attempted to use the code snippet below, but it's not working as expected. Can someone provide guidance on how to achieve ...

How can I create my own unique scrolling behavior in JavaScript?

Looking to create a similar effect as seen on this website: where the vertical scrollbar determines the movement of the browser "viewport" along a set path. I believe that using Javascript to track the scroll bar value and adjust background elements acco ...

Html elements overlapping due to incorrect positioning

I'm having an issue with my div elements on a web page. Despite them being set up separately, they all end up positioned underneath the first div created (SiteFullControl). Is there any solution to prevent this from happening? <div id="SiteFullCo ...

Tips for directing attention to a specific row with an input field in JavaScript

I duplicated a table and added an input field for users to search or focus on a specific row. However, there are two issues: When a user enters a row number, the table displays the wrong row - for example, if the user enters 15, the table shows row number ...

Utilize xdebug and NetBeans 8.2 to troubleshoot PHP code submitted through an HTML form

After successfully setting up the XDebug extension to debug PHP code within NetBeans IDE (ver. 8.2), I encountered an issue. While debugging works fine when setting a breakpoint and running the script in debug mode, I am having trouble debugging PHP code t ...

Dynamic JavaScript button control based on time

I am currently working on an app and my goal is to have a feature where the user clicks a button, it will then disappear and only reappear after 24 hours. Here's my progress so far. <div class="buttons"> <p><button onclick="hide(); ...

Steps for sharing a word file between two users

Can someone help me with sending a file to another user and providing them with a download link? I have already attached the file to the database table of the recipient, but now I need to figure out how to allow them to download and view it. I've hear ...

Center-aligned Bootstrap responsive column with a fixed width

Currently, I am working on creating a login page with a fixed width and a centered column layout. This is similar to the design of the login page at https://www.amazon.com/sign-in. I attempted to achieve this layout using offset columns, as shown below: ...

Consistently directing to a single page on the Node Js web server

I'm in the process of creating a website with multiple HTML pages. Currently, I have code that successfully links to the login page, but unfortunately, the localstores page also directs to the login page. const express = require('express') ...