Tips for placing a searchbox on top of a carousel?

I need to create a search box that overlays on top of a carousel image. I currently have the search box positioned absolutely, but it's not responsive as it doesn't stay within the carousel as the width decreases. How can I make it responsive while staying inside the carousel?

Below is my code:

<div class="container-fluid search_bar"> 
        <row>
                <div class="col-xs-7 search">




        <div class="navbar nav1" role="navigation">

    <div class="navbar-header">

        <form class="navbar-form form1 "  role="search">
        <div class="">

            <input type="text" class="form_input" placeholder="Type Hospital Name" style="float:left; width: 27%; margin-top: 0; margin-right: 3%;" name="srch-term" id="srch-term">
            <select style="float: left; padding: 1px; width: 27%; margin-right: 3%;" class="selectbox1 form_input" >
                <option> Speciality </option>
                <option> Search in Health Packages </option>
                <option> Search in Diagnostic Centres </option>
                <option> Search in Doctors </option>
                <option> Search in Tests </option>
            </select>
            <input type="text" class="form_input" placeholder="Type Location" style="float:left; width: 27%; margin-right: 6" name="srch-term" id="srch-term">
                <button class="form_button" style="padding: 4px;" type="submit"><i class="glyphicon glyphicon-search"></i></button>
        </div>
                    </form>
        </div></div></div>




<div class="col-xs-5" style="border: none !important; ">
                <div class="social-media">
                    <ul class="list-unstyled list-inline">
                        <li> <img src="images/facebook.png" class="img-responsive" style="cursor: pointer;"/> </li>
                        <li> <img src="images/twitter.png" class="img-responsive" style="cursor: pointer;"/> </li>
                        <li> <img src="images/google.png" class="img-responsive" style="cursor: pointer;"/> </li>
                    </ul>
                </div>
            </div>
    </row>
    </div>



    <div class="col-xs-12">
                <div id="myCarousel" class="carousel slide slider" data-ride="carousel">
  <!-- Indicators 
  <ol class="carousel-indicators">
    <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
    <li data-target="#myCarousel" data-slide-to="1"></li>
    <li data-target="#myCarousel" data-slide-to="2"></li>
    <li data-target="#myCarousel" data-slide-to="3"></li>
  </ol> -->

  <!-- Wrapper for slides -->
  <div class="carousel-inner" role="listbox">
    <div class="item active">
        <img src="images/homeimage1.jpg" class="img-responsive" >
    </div>

    <div class="item">
      <img src="images/homeimage1.jpg" class="img-responsive" >
    </div>

    <div class="item">
      <img src="images/homeimage1.jpg" class="img-responsive">
    </div>

    <div class="item">
      <img src="images/homeimage1.jpg" class="img-responsive">
    </div>
  </div>

  <!-- Left and right controls -->

      <div class="right carousel-control" style="right: -5%; cursor: pointer;" href="#myCarousel" data-slide="next">
          <span> <img src="images/right.png" class="img-responsive"/></span>
    </div>
    <div class="left carousel-control" style="left: 4%; cursor: pointer;" href="#myCarousel" data-slide="prev">
        <span> <img src="images/left.png" class="img-responsive"/></span>
    </div>

</div>

    </div>

And here's the corresponding CSS:

.search_bar {
    position: relative;
    top: 91px;
    left: 10%;
    /* margin-left: -0.5%; */
}
.search_bar1 {
    position: absolute;

    z-index: 3;
    margin-top: 8%;
    margin-left: 10% !important;
}

@media (max-width: 768px) {
.search_bar1 {
    margin-top: 0;
}
}

Answer №1

When there is a lot of content in the search bar, it can pose issues on smaller devices. To address this, I have come up with a solution where the search bar will move below the carousel on small displays. This modification allows the search bar to respond dynamically as the screen size changes. Additionally, I have repositioned your social media icons to a new row below the search options for better space utilization. While I may not know all your requirements, I hope these adjustments prove helpful. Feel free to reach out if you have any questions.

.navbar-header { width:100%; }
.search_bar {
    width:50%;
    position: absolute;
    z-index:1;
    top: 91px;
    left: 5%;
}

.search_bar select, .search_bar input, .search_bar button { float:left; margin-top:2px; }

@media (max-width: 500px) {
  .search_bar {
     position:relative;
     top:0;
     left:0;
     width:100%;
  }
}
<div class="col-xs-12">
  <div id="myCarousel" class="carousel slide slider" data-ride="carousel">
    <div class="carousel-inner" role="listbox">
      <div class="item active">
        <img src="images/homeimage1.jpg" class="img-responsive" >
      </div>
      <div class="item">
        <img src="images/homeimage1.jpg" class="img-responsive" >
      </div>

      <div class="item">
        <img src="images/homeimage1.jpg" class="img-responsive">
      </div>

      <div class="item">
        <img src="images/homeimage1.jpg" class="img-responsive">
      </div>
    </div>

    <div class="right carousel-control" style="right: -5%; cursor: pointer;" href="#myCarousel" data-slide="next">
      <span> <img src="images/right.png" class="img-responsive"/></span>
    </div>
    <div class="left carousel-control" style="left: 4%; cursor: pointer;" href="#myCarousel" data-slide="prev">
      <span> <img src="images/left.png" class="img-responsive"/></span>
    </div>
  </div>

<div class="container-fluid search_bar"> 
   <div class="row">
    <div class="col-xs-12 search">
      <div class="navbar nav1" role="navigation">
        <div class="navbar-header">
          <form class="navbar-form form1 "  role="search">
            <input type="text" class="form_input" placeholder="Type Hospital Name" style="margin-top: 0; margin-right: 3%;" name="srch-term" id="srch-

term">
            <select style="float: left; padding: 3px; margin-right: 3%;" class="selectbox1 form_input" >
              <option> Speciality </option>
              <option> Search in Health Packages </option>
              <option> Search in Diagnostic Centres </option>
              <option> Search in  Doctors </option>
              <option> Search in  Tests </option>
            </select>
            <input type="text" class="form_input" placeholder="Type Location" style="margin-right:3%;" name="srch-term" id="srch-term">
            <button class="form_button" style="padding: 4px;" type="submit"><i class="glyphicon glyphicon-search"></i></button>
          </form>
        </div>
      </div>
    </div>
   </div>
   <div class="row">
     <div class="col-xs-12" style="border: none !important; ">
       <div class="social-media">
         <ul class="list-unstyled list-inline">
           <li> <img src="images/facebook.png" class="img-responsive" style="cursor: pointer;"/> </li>
           <li> <img src="images/twitter.png" class="img-responsive" style="cursor: pointer;"/> </li>
           <li> <img src="images/google.png" class="img-responsive" style="cursor: pointer;"/> </li>
          </ul>
         </div>
       </div>
     </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

Enhancing Your Vue Experience: A Guide to Highlighting and Selecting HTML Elements on Mouse Hover

Incorporating a navigation header using Vue, I utilize v-html to display it seamlessly. Check out the demo - here <section class="text-gray-700 font-heading font-medium relative bg-gray-50 bg-opacity-50"> <nav class="flex justify ...

CSS division style not being properly implemented across entire form

I currently have an HTML form linked to a CSS file. Here is the HTML code: .css-form-group{ margin-bottom:10px; clear:both; } .css-form-group label{ font-weight: bold; } .form-input{ float: right; } .form-input:focus{ background: y ...

Toggle the hamburger menu using JavaScript

How can I close my hamburger menu when clicking a link for one page navigation? The menu is functioning properly, but I need a way to close it. Unfortunately, I have limited knowledge of JS. I only have the HTML and CSS for this: HTML in index.html file ...

I recently designed a form using a combination of HTML and JavaScript in order to display different dialogues depending on the number of selections made. Unfortunately, the alert function does not seem to be functioning

The concept is to have users select options and then receive employment sector suggestions based on their selections. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

Error Encountered: Angular JS Throwing Unhandled Injection Error

I am having trouble validating the fields in my index.html and js files. I keep seeing errors, even after trying different versions of angular-route.min.js and angular.js. AngularJs | Basic Login Form <body ng-app="myApp"> ...

Grab all the text using Java Jsoup

I am having an issue with the code I have written. The doc.body.text() statement is not displaying the text content within the style and script tags. I examined the .text() function code and found that it searches for all instances of TextNode. Can someone ...

What is the best way to transform this into an HTML readable code?

While browsing through a template, I came across this code and I'm unsure of how to get it functioning. I've tried removing the comments, but unfortunately it doesn't seem to be working as expected. li.dropdown.navbar-cart ...

Capture various data points in an array with each click

I am currently working on a menu of buttons where users can select multiple options at the same time. My goal is to record all selected buttons in one array instead of individual arrays for each button. The end result I hope to achieve is an array like t ...

Using an npm package to include CSS styles in a stylesheet

I created an NPM package that includes a CSS file that needs to be included in my main CSS file. In a typical HTML CSS website, I would need to write @import url("./node_modules/web-creative-fonts/index.css") but what I really want is to simplify ...

Help me figure out how to independently toggle submenus on my navbar by utilizing the Vue.js composition API

I am currently working on developing a navbar using the Vue.js composition API. My primary objective is to toggle the submenus when a user clicks on them. However, since I am iterating through an object to display the submenus, I am faced with the challeng ...

Guide on how to toggle disabled input text box upon checking checkbox using JavaScript

When the checkbox next to the appended text box is checked, I want to disable that text box. The hard-coded text box is already disabled when its checkbox is checked. You can see the actual outcome by running the code snippet or check out the screenshots b ...

Setting a background image in vanilla-extract/css is a straightforward process that can instantly enhance

I am brand new to using vanilla-extract/CSS and I have a rather straightforward question. I am attempting to apply a background image to the body of my HTML using vanilla-extract, but I am encountering issues as I keep getting a "failed to compile" error. ...

What could be causing the HTML <DATALIST> dropdown to display next to its input rather than below it?

I have an input linked to a datalist, and it's functioning correctly. However, when I initially open the dropdown, the option list appears next to (right of) the input. After entering a few characters to narrow down the list, it then shifts below the ...

What is the best way to assign group headings to my Codeigniter view results?

One of the challenges I'm facing in my view is organizing a list like this: <? foreach($services as $service): ?> <tr> <td><?= $service->name; ?></td> <td><?= $service->format; ?></td> < ...

Update the icon within the expandable display

Is there a way to change the plus sign to a minus sign in an expandable table view on click? (changing fa fa-plus to fa fa-minus) The goal is to have the plus sign displayed when the view is compressed and the minus sign displayed when it is expanded. If ...

What's causing my struggle to override the bootstrap nav-link class in next.js?

I am facing an issue where I need to customize the active state of bootstrap .nav-link in the code snippet below: <li className="nav-item"> <a className={`${styles.navLink} nav-link`} role="tab" data-to ...

The card has adhered itself to the uppermost part of the Bootstrap 4 webpage

I attempted to center the container on the page, but it appears to be stuck at the top instead. I have come across a related question, but the solutions provided did not work for me. I even tried copying some code snippets, but in my Firefox browser, the ...

Enhance your Bootstrap Progress Bar by incorporating the width value within the CSS using CoffeeScript or jQuery

I'm attempting to create a function where every time the button is clicked, the progress bar increases by an extra 12.5% out of the total 100%. (Therefore, eight clicks will complete the progress bar to 100%) Currently, it updates the text content bu ...

Is it possible to use JavaScript to forcefully transition a CSS keyframe animation to its end state?

One dilemma I am facing involves CSS keyframe animations triggered by scroll behavior. When users scroll too quickly, I would like JavaScript to help send some of the animations to their 'finished/final' state, especially since the animations bui ...

Elements with fixed positions in CSS overlapping one another

Hey there, I'm working on a navigation bar and using Jquery to resize elements for better website aesthetics. Instead of a traditional horizontal list, each button is created individually with images: <a href="#" class="button" id="home"><im ...