Dynamic Sizing of Inline Input Fields in Bootstrap 3 Using Narrow Columns

My goal is to create an inline form within a small container (.col-sm-4) without it wrapping into multiple lines. I want the inputs to adjust to the column size while also having the button in the desired position. To achieve this, I have managed to remove the min-width of the inputs but struggle with placing the button correctly. Here is the design I am aiming for:

You can view my progress and code on JSFiddle.

HTML:

<div class="col-xs-4 well">
    <div class="col-xs-7 form-col" id="input-dynamic">
        <input type="text"></input>
    </div>
    <div class="col-xs-4 form-col" id="input-dynamic">
        <div class="input-group-addon">$</div>
        <input type="number"></input>
    </div>
    <div class="col-xs-1 form-col" id="input-dynamic">
        <button class="btn btn-danger">-</button>
    </div>
</div>

CSS:

#input-dynamic input[type=text] {
    width: 100%;
    box-sizing: border-box;
    height: 28px;
}
#input-dynamic input[type=number] {
    width: 100%;
    box-sizing: border-box;
    height: 28px;
}
#input-dynamic button {
    width: 100%;
    box-sizing: border-box;
    height: 28px;
}
.form-col {
    padding-right: 2px;
    padding-left: 2px;
}

Answer №1

Kfriede, Greetings! Your desire to prevent form items from stacking has been noted.
I have provided a solution in the form of a Fiddle specifically designed for this purpose.
To ensure usability on smaller screens, I incorporated a media breakpoint at 320px. This adjustment allows the button to drop below and expands the two inputs to occupy 50% width each.
I hope this setup serves as a solid starting point for your endeavors with this particular form.

<form class="row-fluid">
    <input type="text" class="input-style col-xxs-6 col-xs-4 " id="exampleInputName2" placeholder="Name">  
    <label class="sr-only" for="exampleInputAmount">Amount (in dollars)</label>

    <div class="col-xxs-6 col-xs-5 input-block">
        <div class="input-addon input-height col-xs-2">$</div>
        <input type="text" class="input-style col-xs-8" id="exampleInputAmount" placeholder="Amount">
    </div>

    <div class=" col-xxs-12 col-xs-3">  
        <button type="submit" class="btn btn-success">Submit</button>
    </div>
</form>

Answer №2

I have taken inspiration from your JSFiddle and made some enhancements.

Using the inline-form techniques as discussed here, I have implemented them in the design.

To create certain elements, I utilized a Bootstrap form builder. There are several similar tools available if you search for "Bootstrap form builder".

One observation was that some external resources were missing in the JSFiddle, so I took the liberty to add those as well.

In case of a very small screen, the layout might get compressed. A solution can be using a media query as discussed HERE to adjust the layout for smaller widths.

<div class="container-fluid">
    <div class="row">
        <div class="col-xs-4">
            <form class="form-inline">
                <div class="form-group">
                    <div class="row">
                        <div class="col-xs-6">
                            <input id="textinput" name="textinput" type="text" class="form-control input-md"></div>
                            <div class="col-xs-6"><div class="input-group"> <span class="input-group-addon">$</span>

                                <input id="prependedtext" name="prependedtext" class="form-control" placeholder="Amount" type="text"> <span class="input-group-btn">
        <button class="btn btn-danger" type="button">-</button>
      </span>

                            </div>
                        </div>
                    </div>
            </form>
            </div>
        </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

Should scripts be replayed and styles be refreshed after every route change in single page applications (SPA's)? (Vue / React / Angular)

In the process of creating a scripts and styles manager for a WordPress-based single page application, I initially believed that simply loading missing scripts on each route change would suffice. However, I now understand that certain scripts need to be ex ...

What is the method for identifying the selected radio button that has been dynamically generated after clicking the submit button?

Despite this question being asked multiple times before, I am struggling to find a solution that fits my specific scenario. Initially, I have a static radio button that I create. The HTML code is as follows: <body> &l ...

Adjust the wait time for sliding on the jQuery rcarousel

I am currently utilizing rcarousel for my website and I would like to adjust the duration of time that each slide is displayed. At the moment, each slide stays up for just a few seconds, but I want to extend this so that each slide remains on screen for at ...

Creating a series of spots arranged in a semi-transparent line using JavaScript for a unique canvas

My attempt at creating a highlighter is encountering issues with transparency The problem might be due to using lineCap=round, resulting in multiple dark spots appearing in a single line (which shouldn't happen). It's difficult to fully describe ...

Experiencing Issues with the Email Button Functionality on My Website

I am looking to create an "Email" button that will send the user-entered text to my email address. Here is the code snippet: <form method="post" action="malto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cb ...

What is the best way to align the items in the center of this container?

Check out this link: http://jsfiddle.net/zCXMv/18/ I'm having trouble getting this to work properly. Any assistance would be greatly appreciated. Here is the HTML code snippet: <div id="button" > <a class="button1 active" rel="1">&l ...

Displaying an HTML file in a Node and Express application using JavaScript File handling

Starting my first Node, Express & Angular project has been a bit tricky due to issues with the asset pipeline. I'm not entirely sure if it's related to my folder structure, which I tried setting up based on online tutorials but am open to suggest ...

Can you explain the distinction between escapeXml and escapeHtml functions?

When it comes to escaping characters in JSP pages, I am wondering which is the better option - using escapeXml or escapeHtml? ...

Reveal and Conceal, the ever-changing show

As I work on my blog, I want to make the layout more compact by having a link that reveals comments and entry forms when clicked. I've seen this feature on other sites as "Comments (5)", but I'm unsure how to implement it myself. Below is a snip ...

CSS selector for the 'second next' element, checkboxes and labels within MVC forms

I found a helpful resource that explains how to style checkboxes using CSS. It suggests using the + selector to target the label immediately following the checkbox: input[type="checkbox"]{} input[type="checkbox"] + label {} However, I encountered an issu ...

Display the Currently Searched Value with Select2

I am currently utilizing the Select2 framework along with an ajax call in my project. I have successfully implemented it, but I am facing an issue where the current search value is being displayed as a selectable option even when there are no search result ...

Using Modernizr to determine the presence of nth-child in a test

I'm attempting to utilize modernizr in order to check for browser support of the :nth-child selector, but I am unsure of how to proceed. I came across this particular example on http://jsfiddle.net/laustdeleuran/3rEVe/ which tests for :last-child. How ...

Reactively created menu using JQuery

Looking to implement a dynamic JQuery menu using React (ES6). Utilizing the JQuery menu examples (https://jqueryui.com/menu/) as a guide, however, those examples only cover static menus. It doesn't clarify how to modify menu items like updating labels ...

Leveraging arrays generated from two separate MySQL queries for dual selection functionality with JavaScript

I have successfully populated the first HTML select with results from the first query. Now, I would like to store the results from the second query in either a Json file or XML and then use plain javascript (not jQuery) to populate the second HTML select ...

Retrieving data from a Ruby class based on a specific condition

Currently, I have a code snippet that adjusts the formatting of an editing page based on the number of values a question contains. <% (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aa9b8484eadbdfcfec8cdcac3c5c484dbc6ece0 ...

Automatically switch to the designated tab depending on the URL

Is it possible to automatically activate a specific tab based on the URL structure if my tabs are configured in this way? I am looking for a solution where a link on www.example1.com/notabs.html will redirect to www.example2.com/tabs.html This particular ...

One common issue is being unable to target input[type=file] when multiple forms are present on a page using JavaScript

Question: I have multiple dynamic forms on a web page, each with a file input field. How can I specifically target the correct file input using $(this) in JavaScript? Here is an example of one of my forms: <form enctype="multipart/form-data" action="c ...

Using the transform property with the scale function causes elements positioned in the bottom right corner to vanish

Issue specific to Google Chrome and Windows 10 I'm currently working on a flipbook that adjusts content size using transform:scale() based on the user's screen size. There is also a zoom feature that allows users to adjust the scale factor. I ha ...

scraping mixed content from an HTML span using Selenium and XPath

Currently, I am attempting to extract information from a span element that contains various content. <span id="span-id"> <!--starts with some whitespace--> <b>bold title</b> <br/> text here that I want to grab.... < ...

What is the process for including a field specific to a date in a form?

I need the user to select a month and year. In one column, there will be the days of the month they selected [e.g. 1-30]. Users can then add habits in other columns. I want users to be able to input an 'X' for each habit row on a specific date [e ...