How to Ensure Button and Text Box are the Same Width on Mobile Using Bootstrap?

When viewing on larger screens, the button aligns with the text box in the same line. However, on smaller screens when zoomed in, I want the button to appear below the text box while maintaining the same width. I've been struggling to make it work properly. Here is the code that I have:

<!DOCTYPE html>
<html Lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3a5855554e494e485b4a7a0e140f1409">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
    </head>
    <body>
        <form method="GET" id="target" class="form-inline justify-content-center">
            <div class="form-row justify-content-center text-center">
                <div class="form-group form-inline">                  
                    <input type='text' class ='form-control mb-2 mr-sm-2 mb-sm-0 input-group' id='keyword' maxlength='25' placeholder="Text">
                </div>
                <input type="submit" class="btn btn-primary input-group mb-2 mr-sm-2 mb-sm-0 text-center rounded-0 justify-content-center" value="Text">
            </div>
        </form>
    </body>
</html>

Answer №1

To include the button alongside the input field, place it within the parent div:

<!DOCTYPE html>
<html Lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6c0e0303181f181e0d1c2c584259425f">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
  </head>
  <body>
    <form method="GET" id="target" class="form-inline justify-content-center">
      <div class="form-row justify-content-center text-center">
        <div class="form-group form-inline">                  
         <input type='text' class ='form-control mb-2 mr-sm-2 mb-sm-0 input-group' id='keyword' maxlength='25' placeholder="Text">
         <input type="submit" class="btn btn-primary input-group mb-2 mr-sm-2 mb-sm-0 text-center rounded-0 justify-content-center" value="Text">
       </div>
     </div>
   </form>
 </body>
</html>

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

Error encountered with the @Import rule during CSS Isolation implementation

@import url('https://fonts.googleapis.com/css?family=Playfair+Display:400,400i,700,700i,900,900i'); @import url('https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i,800,800i'); Attempting to use CSS i ...

Troubleshooting: Why Is My Bootstrap 5 Mobile Navigation Bar Not Expanding

As I embark on creating my very first webpage, I wanted to incorporate a responsive navigation bar using Bootstrap 5. Initially, everything was working perfectly until suddenly, the navigation bar stopped functioning properly. While it functions as intende ...

JavaScript | Calculating total and separate scores by moving one div onto another div

I have a fun project in progress involving HTML and Javascript. It's a virtual zoo where you can drag and drop different animals into their designated cages. As you move the animals, the total count of animals in the zoo updates automatically with the ...

Deactivating Cluetip tool tips and adjusting the height limit in JQuery

How can I momentarily turn off the hints? I have seen references to being able to do so on the website and in this forum, but I am having trouble locating the command to disable them. I just need to temporarily deactivate them and then enable them again. ...

What is preventing Facebook from merging its CSS/JS files together?

I wonder about the reasoning behind Facebook developers' decision not to consolidate their scripts and stylesheets into single files, opting instead to load them on demand through their CDN. Considering the complexity of Facebook as an application, I ...

Placing a div with position:absolute inside another div with position:absolute and turning them into position:fixed

HTML <div class="box1"></div> <div class="box2"> <div class="box3"></div> </div> CSS Properties of box1, box2 and box3 are: box1 { position: absolute; z-index: 100; background-color: rgba(39, 39, 39, 0.3) ...

Utilizing Material UI to access CSS classes in React

Seeking guidance on incorporating CSS within another CSS in React using Material-UI. Although I am familiar with using @extends and @mixin for applying CSS rules, I encountered a challenge when working with React and Material-UI. How can I address this iss ...

PHP: Parsing HTML Tables with Headers and Irregular Body Rows Using Simple HTML Dom Parser

In an HTML table, the data is structured as follows: Header 1 has Row 1, Header 2 has Row 2 and Row 3, while Header 3 has Row 4, Row 5, and Row 6. <table> <thead> <tr> <th>Header 1</th> </tr> </thead& ...

Selecting Messages in a Scala Play Application

After running the sample code in play 2.2 "comuputer-database-jpa", I came across a specific part in the Conf/Messages file: # Messages computers.list.title={0,choice,0#No computers|1#One computer|1<{0,number,integer} computers} found I found this co ...

What causes an absolutely positioned element to be positioned by its sibling rather than at the top corner of the page?

Can someone explain to me why my absolutely positioned element is displaying after my child_static div? I'm under the impression that absolutely positioned elements are removed from the normal flow. So why isn't child_absolute covering the child_ ...

error in jquery when splitting

I encountered an issue while trying to split data for checkboxes. var ukuran = data['model'].ukuran_model; var cek = ukuran.split(",").join('], [value='), $inputs = $('input[name^=ukuran]'); $inputs.filter('[value=&a ...

Extract information from a poorly structured PDF chart

Currently, I am facing the challenge of extracting data from a poorly structured PDF document (you can find the URL in the code below). To effectively extract meaningful data records, I will need to leverage the information regarding the position of the li ...

Stretching the final column using Bootstrap

Using Bootstrap, I have created a layout where each width is set to 4 units. https://i.sstatic.net/5TdQc.png This is the desired outcome: https://i.sstatic.net/01m2B.png The goal is for the last elements in the row to stretch and fill the space. If ther ...

Creating a multi-level array or object from a deeply nested HTML list

I'm trying to create an Array that represents the structure of an ordered list. For example, the list would look like this: <ol class="list"> <li><p>1</p> <ol> <li><p>1.1</p>< ...

Creating a default option of "please select" on an Angular select element with a null value for validation

Within my Angular application, I am using a select element with an ngFor loop: <select formControlName="type" required> <option *ngFor="let type of typeList" [ngValue]="type.value">{{ type.caption }}</option> </select> When view ...

The JQuery .replaceWith method exclusively offers unprocessed HTML content

I'm experiencing a minor issue with my ajax response where it returns raw html and does not execute any scripts, resulting in the jquery ui scripts not being executed. Here are some details: I am currently working with ASP.NET MVC and I need to comm ...

What is the best way to navigate to a new sub-page within a project: opening it in the current tab or

I just finished creating a single page website that scrolls to its respective sections when clicking on the navigation bar. I have also applied a script for this functionality. //smooth scroll to href value jQuery(".tabs-btn ul li a, .navbar-nav li a, .n ...

Using HTML code to incorporate one HTML file into another's structure

As a skilled programmer, I understand the importance of code reusability. Despite being new to HTML and CSS programming, I often find myself writing repetitive code in one HTML file. Is there a way to avoid this redundancy? Can functions be utilized in H ...

Any tips on sending looping values to a Bootstrap modal?

Introduction: Despite researching solutions for passing variables into a Bootstrap modal, none of them seem to solve my particular issue. I am currently iterating over a JSON object that contains image URLs and an array of comments related to each image. ...

Selenium: What causes the CSS selector to fail in IE10 while working fine in Firefox and Chrome?

from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC wait = WebDriverWait(webdriver, 10) elem = wait.until(EC.visibility_of_element_located( (By.CSS_SELECTOR, '.top_laye ...