Center items in a Bootstrap collapsed menu

I have put together a bootsrap page with a collapsible search bar. I am looking to make some modifications to it.

  1. My first goal is to expand the width and center the bar only when in the collapsible view.
  2. When the size decreases to 'sm', I would like the input field to change to 100% width, while keeping the button on the same line so that the input + button together equal 100% width.

What would be the most effective approach to achieve this?

Answer №1

For extra-small screens, the form-control is set to display: block and width: 100%. At small screens (≥576px), form-control switches to display: inline-block and width: auto. If you want your search box and button to always be on one line, then add the display and width settings for all screens.

To have the search form always in the center for medium and smaller screens, add justify-content-center to the form and use the left auto margin just on larger displays.

To have the search form and button take up 100% of the available width, add flex-grow-1 to the input (or you could give the input a class of w-75 and it will be larger, but not too big).

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>

<style>
    .form-inline .form-control {
        display: inline-block;
        width: auto;
        vertical-align: middle;
    }
</style>

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

The challenge of removing an event listener

There are three Div elements with a box appearance. When the user clicks on any div, a copy of that div will be added to the end. The original clicked div will no longer be clickable, but the new div will be. This process can repeat indefinitely. I attemp ...

Ionic directive ng-disabled not functioning as expected

Upon running the Ionic application, I noticed that the radio button is not being disabled even with the use of ng-hide.<input type="radio" ng-disabled="true"> ...

How does the emoticon code work in Facebook chat?

Just came across this hilarious website here. LOL! I noticed that on Facebook chat, you can insert emoticon photo codes along with text, just like some kind of Facebook API code. With the help of the FB Photo Zoom Google Chrome plug-in, I discovered that ...

Issues encountered when attempting to incorporate additional sliders using JavaScript within a single webpage

I've been working on integrating a new slider into my website (it would be the 3rd one as I already have 2), but I'm facing some difficulty. I am using JavaScript, but struggling with how to assign and manage the slide numbers like (1,0) or (1,1) ...

What could be causing the React state (array) to be empty within a callback function? Why is it failing to utilize the latest value from the external

I'm facing a challenge that has me stumped. I am attempting to add values to an existing array, but for some reason, the 'state' variable is always empty inside the onmessage callback function. I can't seem to figure out why this is hap ...

Does the zoom value in the HTML file adjust when I zoom in or out on the Google Map?

I'm uncertain if my question is sufficiently clear. Here's my dilemma: I've been utilizing the gmplot module in Python and I'm interested in adjusting the grids to be scalable based on the zoom level of the Google Map. However, being u ...

Populating arrays with prompts using javascript

I'm currently working on a task that involves prompting the user to input random numbers until they enter "-1". Once this condition is met, I need to calculate the average of all the numbers entered excluding "-1". So far, here's what my code loo ...

Error 405 (Method Not Allowed) detected on a ReactJS component

I am attempting to initiate a call to an endpoint using the POST method. Below is the corresponding code: import React, { Component } from 'react'; import { Input} from 'antd'; import Form from '../../components/uielements/form&a ...

Creating unique geometric designs with three.js

Attempting to construct a polygon in three.js and here is the code used for it. function DeployZone(coordinatesList) { // Forming the polygon Shape { var material = new THREE.MeshLambertMaterial({ color: 0x00ffcc }); var faces = [0, 1, 2, 3, 4] ...

Dealing with an endless loop caused by a promise in AngularJS's ui router $stateChangeStart event

I am currently working on implementing authentication in my Angular application and I want to redirect to an external URL when a user is not logged in (based on a $http.get request). However, I seem to be stuck in an infinite loop when using event.prevent ...

Update and republish an outdated npm package

After successfully publishing an npm package, I attempted to make an update which unfortunately resulted in some issues. It seems that I made a mistake during the build process. Since it had been a year since my last update, I have forgotten the exact step ...

Issue with Vue and Firebase: New users are being created successfully, but are being logged into existing user accounts

I've encountered a strange issue in Firebase. When I create a new user with the same password as an existing user, the new user is logged in under the previous user's account and displays all their information. However, upon logging out and signi ...

Ways to enlarge the font size of text on a mobile website?

this is the site i have added viewport, but with image, the text saw on phone is small, how to make the text bigger when see on the phone, what should I add to the code? this is the site i have added viewport, but with image, the text saw on phone is sm ...

Using a combination of jQuery and JavaScript to switch image tags between different classes

I'm really struggling with this issue and could use some guidance. Essentially, I have a code that should change the class of an img tag when a user clicks on a div element. Let's take a look at the HTML structure: <li><img src ...

How should one go about organizing the JavaScript code for a complex application?

Imagine you are working on a complex project with extensive use of JavaScript throughout the site. Even if you divide the JavaScript into one file per page, there could still be around 100 JavaScript files in total. What strategies can you implement to ma ...

Creating React components through the use of the map function

Utilizing the hackernews api, I am attempting to extract the "data" property from my response object in order to display each story title individually on the browser. Initially, the data is structured as an array of id's representing individual storie ...

Gathering information from mapped objects when they are clicked in a React application

Do you know how to retrieve genre.id when a user clicks on a Button and triggers the onClick function? Your assistance is greatly appreciated. ... return ( <div className="App"> <Header /> <div className="A ...

I am currently in the process of conducting an automated test focused on the creation of a new Facebook account

I am currently facing a challenge while attempting an automated test on Facebook. The issue lies in clicking the "Create Account" button using FindElement by id, which is not functioning as expected. public void createAccount(String firstName, String lastN ...

Enhance Website Functionality with Dynamic Tables and Spreadsheet Features

Currently, I need to incorporate spreadsheet-like functions into a table on my website. Initially, I explored KendoUI but realized it might not be within my budget constraints. Is there a more affordable alternative available? Key features I require inclu ...