Struggling to align the search box in the center of the Bootstrap navbar

I'm currently working with a static bootstrap navbar and trying to center a search box within it. Unfortunately, all my attempts have been unsuccessful so far. The search box either appears below the navbar or doesn't display at all. At this point, I've managed to make it visible, but it's positioned above the navbar title on the left side, not aligning vertically with the rest of the navbar items. I've experimented with using just a form, the navbar-center class, and now a div element, but none of them seem to be working as expected. It feels like there must be a simple Bootstrap class or CSS property that I'm overlooking.

    <nav class="navbar navbar-default ">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>
            <a class="navbar-brand" href="index.html"><img src="static/img/CAP-Seal-75x75.png" width=50 height=50 ></a>
            <p style="padding-top:25px;width:120%;"></span>CAWG (TRACS) </p>
        </div>
        <div id="search" class="nav navbar-nav navbar-center">
        <form class="nav navbar-nav navbar-center" role="search">
            <input type="text" class="search form-control input-sm" placeholder="Search" id="sitesearch">
                <button type="submit" class="btn btn-xs"><span class="glyphicon glyphicon-search"></span></button>
                </form>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav navbar-right" style="padding-right:20px;">
            <ul class="nav navbar-nav">
                <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <span class="glyphicon glyphicon-th-list" aria-hidden="true" style="font-size:1.5em;"></span><i class="icon-angle-down"> </i></a>
                    <ul class="dropdown-menu">
                        <li><a href="#track_modal_realtime"  data-toggle="modal">Real Time Tracking</a></li>
                        <li><a id="stop_tracking" href="#">Stop Tracking</a></li>
                        <li><a href="#track_modal_historical"  data-toggle="modal">Historical Tracking</a></li>
                        <li><a href="#send_message_modal"  data-toggle="modal">Communications</a></li>
                    </ul>
                </li>
                <li>
                    <a class="navbar-brand" href="#menu-toggle" id="menu-toggle"><span class="glyphicon glyphicon-resize-full" aria-hidden="true" id="sizeIcon" style="font-size:1.5em;"></span></a></li><!---->
                <li><a href="#settings_modal" data-toggle="modal"><span class="glyphicon glyphicon-cog" style="font-size:1.5em;" aria-hidden="true"></span></a></li>
            </ul>

        </div>
    </nav>

Do you have any suggestions or ideas that might help me solve this issue?

Thank you in advance!

Answer №1

Maybe I have comprehended your query correctly. In that case, you may consider implementing something along these lines:

   <nav class="navbar navbar-default ">
 <div class="row">
   <div class="col-sm-4">
    <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar">                   </span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>
        <a class="navbar-brand" href="index.html"><img src="static/img/CAP-Seal-75x75.png" width=50 height=50 ></a>
        <p style="padding-top:25px;width:120%;"></span>CAWG (TRACS) </p>
    </div>
  </div>
  <div class="col-sm-4">
    <div id="search" class="nav navbar-nav navbar-center">
      <form class="nav navbar-nav navbar-center" role="search">
        <div class="input-group">
          <input type="text" class="search form-control input-sm" placeholder="Search" id="sitesearch">
          <span class="input-group-addon" id="basic-addon2"><span class="glyphicon glyphicon-search"></span></span>
        </div>
      </form>
    </div>
  </div>
  <div class="col-sm-4">
    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav navbar-right" style="padding-right:20px;">
        <ul class="nav navbar-nav">
          <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> <span class="glyphicon glyphicon-th-list" aria-hidden="true" style="font-size:1.5em;"></span><i class="icon-angle-down"> </i></a>
            <ul class="dropdown-menu">
              <li><a href="#track_modal_realtime"  data-toggle="modal">Real Time Tracking</a></li>
              <li><a id="stop_tracking" href="#">Stop Tracking</a></li>
              <li><a href="#track_modal_historical"  data-toggle="modal">Historical Tracking</a></li>
              <li><a href="#send_message_modal"  data-toggle="modal">Communications</a></li>
            </ul>
          </li>
          <li>
            <a class="navbar-brand" href="#menu-toggle" id="menu-toggle"><span class="glyphicon glyphicon-resize-full" aria-hidden="true" id="sizeIcon" style="font-size:1.5em;"></span></a></li><!---->
          <li><a href="#settings_modal" data-toggle="modal"><span class="glyphicon glyphicon-cog" style="font-size:1.5em;" aria-hidden="true"></span></a></li>
        </ul>
        </div>
    </div>
  </div>
</nav>

You can effortlessly center elements by dividing your nav into 3 parts using Bootstrap's built-in cols.

I hope this meets your requirements :)

See a working instance here - https://codepen.io/anon/pen/ZyMZrY

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

Displaying data from a JSON object to a DOM table can be achieved by dynamically generating table columns based on the keys within

There is a JSON object that I'm working with: [ { "SysID": "4", "Defect Classification": "Wrong Image Color", "1": "3.0", "2": "", "3": " ...

Responsive Input Navigation Bar CSS

How can I create a top bar that resembles the design of Google Play? https://i.sstatic.net/tdLVz.png I am struggling to make the input box flexible and fit the window size... The minimum width of Div.search is set to 250px but it's not working ...

Adding a button label value to a FormGroup in Angular

I've been working on a contact form that includes inputs and a dropdown selection. To handle the dropdown, I decided to use the ng-Bootstrap library which involves a button, dropdown menu, and dropdown items. However, I'm facing difficulties inte ...

CSS: Breaking free from the constraints of a Bootstrap-inspired grid layout

Looking to create a template with a background on the left side that extends to the edge of the page within an 8 of 12 bootstrap columns setup. The remaining 4 columns on the right will not have a background. This layout should be responsive, stacking on t ...

Creating a dynamic button with Angular that appears when focused

I want to have a button appear when the user focuses on an input with the ng-model=query. I know there is an ng-focus directive, but how can I implement it? <input type="search" ng-model="query"> <!--this is the button I need to show once th ...

Generating a dataframe with cells that have a combination of regular and italicized text using the sjPlot package functions

I've been trying to set up a basic data table where the genus name in the "Coral_taxon" column is italicized, but the "spp." part following it remains lowercase. I thought of using the expression() function for each row in "Coral_taxon," but so far, I ...

Encountering a problem with serializing forms using jQuery

Currently, I am working on form serialization in order to send the file name to the server. However, I have encountered an issue where the serialization values are empty and I am expecting the file name to be included. Within my form, there is an HTML fil ...

Tips for entering the lowest and highest values into the input field

I am looking to track the daily minimum and maximum prices of shares for various companies. Currently, I'm attempting to utilize this tag: <input type="number" name="number" placeholder="minprice"> <input type="number" name="number" place ...

What's the best way to make div columns appear closer together when floating?

Check out My CodePen: http://example.com/codepen Hello there, today I am working on a 6-column layout with 3 columns in each row. The 3rd column is quite long and resembles a sidebar. According to the design, columns 4 and 5 should be positioned close to ...

Ensure the TUMBLR og:image appears in larger dimensions for enhanced visibility [updated: additional code implemented]

I recently incorporated two widgets into my blog - one on the sidebar and another attached to each post. You can check them out at . To enhance the visual appeal, I uploaded a 900x900 og:image to the tumblr static servers, accessible through my FB Debug p ...

The fading effects are not functioning as expected in the following code

Hey there, I'm not the most tech-savvy person, but I managed to come up with this code for page redirection. Unfortunately, I couldn't quite get the fade out and fade in effects to work properly when executing it. If anyone out there can help me ...

Bootstrap sliders stagnant and unresponsive

I am encountering an issue with my bootstrap carousel slide. I have configured the buttons and set it to slide automatically, but for some reason, the carousel is not moving when I click on the buttons. I can't figure out what mistake I might be makin ...

Unable to close Bootstrap modal upon clicking "x" or "close" buttons

Hey everyone, I'm having a bit of trouble with my modal. It appears correctly when clicked to open, and the close buttons seem to detect that my mouse is hovering over them. However, when I click on the buttons, nothing happens and the modal remains o ...

Update the div tag container after resizing it

Using bootstrap alongside Jquery/Javascript and Leaflet maps, I am facing an issue. Inside the pBody div lies the map div, along with a sidebar div. The toggle switch above collapses the sidebar div and should expand the width of the pBody div from span9 t ...

Tips for eliminating padding at the top and bottom of a navigation bar

I'm looking to remove the top and bottom padding from my navbar to give it a similar look to the navbar on Wix.com. I've spent most of today trying to figure this out. I've attempted to remove padding with !important from the navbar, tried u ...

Setting MenuItem to the correct width in asp.net simplified

I have a 1000px wide container, within it there is a menu control with 5 items (links). Each item has a width of 200px in the CSS file to make use of the entire length of the line. .level1 { border-width: 0px; margin: 0px; padding: 0px; background ...

How do you transfer drop-down values from an HTML template to views in Django?

I am trying to figure out how to pass the selected option value in a drop down menu to the views. The HTML code of my template is as follows: <select name="version" id="version" onchange="location = this.value;"> &l ...

html - Bootstrap Navbar - Tips for aligning content on both sides

Exploring new frontiers with Bootstrap in Angular. I have successfully integrated a Bootstrap template navbar into my html-site. The navbar consists of text items in an ordered list and a search button along with a related form. My goal is to align the tex ...

Creating a dynamic hover drop-down navigation bar in ASP.NET

After successfully creating a navigation bar with hover effects, I am now looking to implement a dropdown list when hovering over the items. Can anyone provide guidance on how to achieve this? Below is the current code snippet I am working with: <ul c ...

What is the best method for showcasing two images side by side in a column layout?

I need to showcase 2 images in a row using AngularJS, with the next two images in the following row and so forth. Img1 Img2 Img3 Img4 This is my code: <section id="content"> <div class="content-wrap"> <div class="container clearfix "& ...