Position group elements in a row to the right

How can I align the input-group element and button to the right without specifying fixed widths or column sizes? Specifically, I want the col containing the button to only occupy the width of the button itself, with the remaining col being used by the input elements.

Is there a way to achieve this layout using Bootstrap classes?

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

    <div class="col-4">
      <input class="form-control border-basic" id="searchInput" type="text" placeholder="Search Reports..">
    </div>

    <div class="col-8">
    
      <form class="float-right" method="post" style="width:50%">
        <div class="form-group row text-right">
          <div class="col">
            <div class="input-group" style="text-align:right;">
              <input class="form-control border-info"  type="text" name="name" placeholder="Enter here" required>
              <div class="input-group-append">
                <button class="btn btn-outline-danger border-info" type="button" title="Clear">
                  <i class="fa fa-close fa-lg"></i>
                </button>
              </div>
            </div>
          </div>
          
          <div class="col">
            <button class="btn btn-danger" type="submit" title="Add"><i class="fa fa-plus-circle fa-lg"></i> Create</button>
          </div>
          
        </div>
      </form>
    </div>
  </div>
</div>

https://jsfiddle.net/4fn1sz30/39/

Answer №1

Swap out col-auto for better results. This will allow the column to adjust to the width of its content:

<div class="adjustable-col">
     <button class="btn btn-primary" type="submit" title="Submit"><i class="fa fa-check-circle fa-lg"></i> Submit</button>
</div>

https://example.com/code-demo123

Answer №2

Updated the classes from col-4 to col-md-4, col-sm-4, col-xs-4 and col-md-8, col-sm-8, col-xs-8.

While col-4 works fine, consider using Bootstrap for responsive design by specifying different column sizes for various device resolutions.

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

Connecting CSS Style Sheet to JSP Page

I'm facing an issue with linking a CSS file located in my WEB-INF folder to a JSP page. In the JSP page, I have specified the location of the CSS file as follows: <link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/WEB- ...

An easy way to attach a Contextmenu to a specific element

I have implemented a scrolling feature for one of the div elements in my Application. Inside this div, there is a templated table with over 100 rows. Users are able to add or delete rows using a contextMenu. The contextMenu offers 4 options - AddTop, AddB ...

obtain the image number by extracting a portion of the text

How can I extract the image number from a string using the sub-string function? I have applied the sub-string function to the property below. It returns 3 at the end in Chrome, but it does not work properly in Mozilla. Issue : After "-->", when I chec ...

Launching a modal in a new browser window with the help of JavaScript or PHP

I need to implement a feature where clicking a link opens a modal in a new tab and redirects the current page to a different link, similar to how retailmenot handles coupons. Here is the code snippet I am currently working with: <div onClick="myFunctio ...

Exploring the Potential of CSS Styling within Vue.js

I am in the process of creating a website and I am looking for a way to manage my styles through Vue. I want to be able to utilize CSS with Vue, as the style of .skill-bar serves as the background of the bar, while .skill-bar-fill represents the green fil ...

GWT Designer style issue plaguing development efforts

Currently, I am working on designing a login view using GWT Designer while incorporating styles from Twitter Bootstrap. The structure I have set up is as follows: However, the displayed result does not meet my expectations: Despite setting all CSS paddi ...

Ways to retrieve nested #document within html?

Hey there! I'm trying to figure out how to use document.querySelector() to locate span id='t1', but I'm unsure of how to access the #document element and its contents. Is it possible to select elements within #document? Currently, I ha ...

Having trouble getting jquery to filter json data based on the selected option

I have developed a code using jQuery to filter the options in a drop-down list based on the selection made. The data is in JSON format and is fetched from a database. However, when I select an option from the drop-down list, the code does not enter the loo ...

Using JQuery to switch classes and activate events

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <body> <span class="fake_h">Too</span> </body> <script> $('.fake_h').click(function() { $(this).addClass( ...

How come the focus doesn't work when altering the CSS code simultaneously?

My attempt at creating a user interface involved an issue where the input field was not visible initially. After clicking the button, the input would appear on the screen, and I wanted to automatically focus on it. This is what I tried to achieve: Initial ...

multiple elements sharing identical CSS styling

For each component, I made separate CSS files and imported them accordingly. However, despite the individual styling efforts, all components seem to have the same appearance. I specifically worked on styling an image differently for two components, but w ...

Why does everything seem to move in sync with the table's scrolling?

I recently had an issue resolved that fixed most of my concerns: I needed to make three separate edits, and now when I reintroduce the other two edits, they are included within the table section and scroll along with the table instead of being stuck beneat ...

Triggering an event for a div using Javascript, along with a Rails loop

I have a page showcasing a collection of listings that are displayed on the main page. <% @listings.each do |listing| %> # do something <% end %> Each listing now includes a data-toggle, essentially a button. <a id="chat-menu-toggle" h ...

Basic stacked or segmented bar in HTML

Instead of starting from scratch, I'm in search of insights on how to develop a stacked/segmented bar or find an existing control for this purpose. Here are my requirements: Horizontal bar Standard html Color-coded segments using CSS Segments propor ...

Creating a popup window using HTML

I am attempting to create a pop-up window using HTML, but I'm struggling to get it to appear in the desired way. My goal is this: to have a pop-up show up when the profile image is clicked on. Here's the HTML <span class="profile"><im ...

Guide to aligning a WordPress div to the top of the webpage

Currently, I am in the process of creating a page template that features a transparent header. My main goal is to have the #content div align perfectly with the top of the page right below the header. I have experimented with various CSS properties such a ...

Retrieving Data from an Unnamed HTML Table using Selenium

I'm currently exploring ways to extract the output generated by this website: mailtester.com upon inputting a complete email. Let's take the email address [email protected] for demonstration. Once this address is entered and submission is ma ...

How to notify when the value of multiple inputs changes using an Angular repeater

I am currently utilizing Angular to generate multiple inputs based on user needs. Although this approach works well, I am struggling to implement a simple alert that would display the values of these inputs. I have managed to retrieve the input values wi ...

Why is it that using div with a 100% width doesn't behave as one would anticipate?

Learning CSS has been an interesting journey so far. It's not always as intuitive as one might think, especially in web development. :) I recently attempted to create a simple, static progress bar using the following HTML file: <html> <he ...

Tips for containing a range slider within a div element in a flexbox container

I am currently using Javascript to generate a grid of images, and I want to include a range slider at the bottom of one of the images. Here is a simplified version of my code using flex-container: <style> .flex-container { display: flex; fle ...