Tips on incorporating a search button into a search bar using Bootstrap

I am looking to add a search bar with a search button inside for my project, similar to this design: https://i.sstatic.net/7f1IN.png

Below is the HTML code I currently have:

<section id="search-section">
  <div class="container-fluid">
      <h3 class="text-center pt-4">Search for Courses</h3>

      <div class="container-fluid text-center pt-3 outbox">
        <div class='row'>
            <div class='col'>
                <form class='order-1'>
                    <input type="text" class='form-control d-inline'>
                    <button class='btn btn-md btn-primary d-inline'>Search</button>
                </form>
            </div>
        </div>
    </div>

  </div>
</section>

Here is the custom CSS applied:

#search-section form {
border: 1px solid black;
display: inline-block;
width: 900px;
padding-bottom:55px;
border-radius: 5px;
background-color:white;
height:50px;
box-shadow: 3px 4px 4px rgba(0, 0, 0, .13);
}

#search-section input[type='text'] {
width:800px;
height:50px;
border:none;
}
#search-section button {
margin-left:10px;
margin-right:5px;
}

.outbox {
height: 500px;
}
.form-control:active,
.form-control:focus {
border: none;
outline: none;
box-shadow: none;
}

The issue I am facing is that the layout works well on larger screens but becomes unresponsive on smaller devices. I aim to adjust it so that on small screens, the search bar and button stack vertically.

Answer №1

One way to optimize your code is by reducing the amount of custom CSS you use, particularly avoiding static widths. By incorporating responsive utility classes, you can effectively position elements like the search input and button...

<section id="search-section">
    <div class="container-fluid">
        <h3 class="text-center pt-4">Search for Courses</h3>
        <div class="container-fluid text-center pt-3 outbox">
            <div class='row'>
                <div class='col-lg-8 col-md-10 col-sm-11 mx-auto'>
                    <form class='order-1 d-flex flex-sm-row flex-column align-items-center'>
                        <input type="text" class='border-0 form-control h-100 mt-2 mt-sm-0'>
                        <button class='btn btn-primary mr-sm-1 mt-4 mt-sm-0 flex-fill'>Search</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</section>

#search-section form {
    border: 1px solid black;
    border-radius: 5px;
    background-color: white;
    height: 50px;
    box-shadow: 3px 4px 4px rgba(0, 0, 0, .13);
}

.outbox {
    height: 500px;
}

.form-control:active,
.form-control:focus {
    border: none;
    outline: none;
    box-shadow: none;
}

https://codeply.com/p/Zl0wdGhJVH

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

You cannot declare a selected option within an HTML select element

I am working on a project that involves setting the selected option as the first service in my Service List. I came across this code snippet that has worked for other instances but not in this case. I'm trying to figure out why, public Servicelist: Ar ...

Alter the tab's color upon clicking the button

I am working on a multi-step form and I wanted to enhance the user experience by adding a button at the bottom of the page for easy navigation instead of relying on tabs at the top. Although the button functions as intended, there is an issue with the tab ...

What are the sequential steps to create a CSS/HTML layout efficiently?

As a developer who is familiar with print design but new to web design, I have a designer assisting me in this transition. While I don't need tips on design or usability, I am eager to learn about the step-by-step process of coding a webpage. I want t ...

Utilizing AJAX to dynamically populate an HTML list from a database and then saving the user's newly selected value back to the database

I'm working on dynamically populating a list from a database using AJAX and then updating the selected value back to the database with a servlet. What's the best approach for achieving this? Typically, I use the following code for dynamic update ...

How can AngularJS store a collection of values obtained from an HTTP GET request?

By making a call to the $resource URL from the controller, I am able to retrieve a list that is visible in the logs. Controller function ClubDetailController($scope, $rootScope, $stateParams, $resource, DataUtils, entity, Club) { var vm = this; ...

What is the best way to utilize the features of component A within component B when they exist as separate entities

Component A has all the necessary functionalities, and I want to use it in Component B. The code for ComponentA.ts is extensive, but it's not written in a service. How can I utilize the logic from Component A without using a service, considering both ...

`Understanding Unique Identifiers in HTML: Questions on Element Naming`

Is it problematic to use a space character in an element ID? For example, like this: <li id='something with spaces'>Test123</li> I typically avoid using spaces in IDs, but I've encountered a situation where it might be necessar ...

Do you have any suggestions on how to send "iframe.contents()" to a PHP Script via Ajax?

I'm currently facing an issue in my code where I have an iFrame loading dynamic content, similar to a webpage (B.html) inside another page (A.php). On "A.php", users can edit the content of "B.html" inline. However, after the editing process is comple ...

Validating (Update database with correct email and token)

Authentication (Update database if email and token are accurate) Even when the code is incorrect, it displays "Great Success", but the status does not update in my database. However, if I input the correct code, it shows "Great Success" and updates the s ...

Ways to conceal components of an external widget on my site

I'm attempting to add a chat widget to my website and I'm looking to hide specific elements within the widget. The chat function is provided by Tidio, but I believe this applies to most widgets. My main goal is to conceal a button that minimize ...

I am facing an issue where the state in Next.js React does not get updated when passing a

"use client"; import { EntityType, World } from "@/types/World"; import React, { useState } from "react"; import dynamic from "next/dynamic"; ; let RayTracingPage = dynamic(()=>import("./RayTracingCanvas&qu ...

When is it appropriate to utilize the prefixes -moz, -webkit, -o within CSS rather than just using basic properties?

When building WordPress themes, is it necessary to use all browser properties instead of just one? For example, we have written the following code for the "transition" property: transition: all 350ms ease-in-out; We see that this works in all modern ver ...

What is the best way to insert a <div class="row"> every 2 items in a Vue.JS template loop?

In my model, I have an array of images' URLs of varying lengths. I want to display 2 images per row on my page, resulting in the following layout: <div class="row"> <div class="col"> <img ... /> </div& ...

Automatically align to the main grid when dragging begins

Hi there! I'm still getting my feet wet in the world of JavaScript and JQuery, so please bear with me if I'm missing a few tricks. I have managed to make JQuery UI draggable elements align to a grid after the page loads, but I'm struggling ...

Is there a way to align my two tables next to each other using CSS?

.page { display: grid; grid-template-columns: 1fr 1fr; grid-gap: 20px; } .items { float: left; } .secondItem { vertical-align: text-top; float: right; } .page-header table, th, td { border: 1px solid; display: block; background-color: ...

What is the best way to bring in an HTML file into a Python variable?

I'm in the process of creating an HTML email using Python, MIMEMultipart, and SMTP. Since the HTML content is lengthy, I decided to store it in a separate HTML file. Now, my goal is to import this HTML file into my Python script (located in the same d ...

Guidelines for comparing two distinct dates using jQuery

const currentDate = $("#date").text(); // the current date is set as a variable 01/06/2017 // Another date is declared as a variable let startDate = '01 / 06 / 2017'; if (currentDate == startDate) {} if (currentDate < startDate) {} <script ...

Guide on displaying the name attribute of a button along with its price in a separate div when clicked

Upon clicking the Koala button, I want to display a message showing the id name of the button and the corresponding price for Koalas. Here is the HTML code snippet: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <link h ...

Exploring Pseudo Classes in Oracle ADF

Within my skin file (which is an extension of Skyros), I have defined a rule as: .arrow_box:after { /*insert some css rules here*/ } .arrow_box:before { /*insert some css rules here*/ } The goal is to generate an arrow on the top of the box simila ...

Is it possible for individuals on the local network to view the webpage?

Recently, I developed a login page in HTML that prompts users for their username and password. The information is then sent to ABC.php, and upon successful authentication, they are redirected to another website. To make this work, I set up a xampp server. ...