Creating a dynamic navigation bar featuring an interactive search option

I am currently working on creating a responsive navigation bar with bootstrap, similar to the one shown in this example.

However, I am facing issues with aligning the search button correctly and ensuring that the tabs remain intact when collapsed. Instead of the Download Wordpress button, I would like to include LogIn and SignUp buttons. When collapsed, I want the brand name, search button, and menu toggle bars to be displayed on the same line.

Could someone please advise me on how to achieve this? You can view my code here.

<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-1">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
    </button>

    <a class="navbar-brand" href="#">Brand Name</a>

    <form class="navbar-form navbar-right" style="float: right;" role="search">
        <input type="text" class="form-control" placeholder="Search">
    </form>
</div>

<div style="clear:both"></div>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="navbar-collapse-1">
    <ul class="nav navbar-nav navbar-left">
        <li class="active"><a href="#">Home</a></li>
        <li><a href="#">Highlights</a></li>
        <li><a href="#">Test Yourself</a></li>
        <li><a href="#">Interesting Questions</a></li>
        <li><a href="#">Ask Queries</a></li>
    </ul>

    <ul class="nav navbar-nav navbar-right">
        <li><a href="#">SignUp</a></li>
        <li><a href="#">LogIn</a></li>
    </ul>
</div>
</div>
</nav>

.navbar {
min-height: 120px;
}

.navbar .container {
padding-top: 20px;
padding-bottom: 20px;
}

.navbar-nav>li>a {
text-transform: uppercase;
font-family: "jokerman";
font-size: 16px;
}

@media (min-width: 768px)   {
.navbar-nav {
margin: 0 auto;
display: table;
table-layout: fixed;
float:  none;
}
}

Answer №1

Here is an example I created for you to demonstrate keeping things simple. Feel free to utilize this code and adjust it for mobile using css3 media queries.

You can also add the following CSS:

position:absolute;right:7px;

to place the menu toggle button on the right for mobile, and you can also use:

position:absolute;left:7px;

to position the ul on the left. Best of luck - Millzie :)

<html>
<head>
<title>My menu V.1</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
 jQuery(document).ready(function($){
  $('.menu-right').click(function(){
   var animationTime = 800;
   if($('.menu').css('height') == '60px'){
    $('.menu').animate({'height':'80px'}, animationTime, 'linear');
   }else if($('.menu').css('height') == '80px'){
    $('.menu').animate({'height':'60px'}, animationTime, 'linear');
   }
  });
 });
</script>
<style type="text/css">
 *{margin:0;padding:0;border:0;border-radius:0;font-family:sans;}
 div.menu{width:100%;height:60px;background-color:#660033;overflow:hidden;}
 ul.menu-ul{float:left;padding-left:7px;}
 li.menu-li{display:inline;list-style:none;font-size:15px;line-height:60px;margin-right:7px;}
 li.menu-li:hover{border-bottom:2px solid #FFFFFF;color:#FFFFFF;}
 div.menu-right{float:right;line-height:60px;font-size:15px;margin-right:7px;}
 div.menu-right:hover{color:#FFFFFF;}
 /*search form*/
 input.search{width:900px;height:20px;margin-top:-3px;margin-left:7px;background-color:#FFFFFF;}
 input.search-button{width:70px;height:20px;margin-top:-3px;margin-left:4px;background-color:#FFFFFF;}
 </style>
</head>
<body>
 <div class="menu">
  <ul class="menu-ul">
   <li class="menu-li">Menu item one</li>
   <li class="menu-li">Menu item two</li>
   <li class="menu-li">Menu item three</li>
   <li class="menu-li">Menu item four</li>
   <li class="menu-li">Menu item five</li>
  </ul>
  <div class="menu-right">Search</div>
  <form>
   <input type="text" class="search" value="search for something" />
   <input type="submit" class="search-button" value="search" />
  </form>
 </div>
</body>
</html>

Answer №2

I'm unsure if your search-input should be visible in xs view, but I have a solution that works:

Check out this Js Fidlle example: http://jsfiddle.net/8hrnkbaL/1/

The initial issue in your fiddle was that bootstrap was loaded before jQuery, however, jQuery needs to load first...

Here's the HTML code snippet:

<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">

        <div class="container">

            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-1">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>

                <a class="navbar-brand" href="#">Brand Name</a>
            </div>

            </div>

            <div style="clear:both"></div>

            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="navbar-collapse-1">
                <ul class="nav navbar-nav navbar-left">
                    <li class="active"><a href="#">Home</a></li>
                    <li><a href="#">Highlights</a></li>
                    <li><a href="#">Test Yourself</a></li>
                    <li><a href="#">Interesting Questions</a></li>
                    <li><a href="#">Ask Queries</a></li>
                </ul>

                <ul class="nav navbar-nav navbar-right">
                    <li><a href="#">SignUp</a></li>
                    <li><a href="#">LogIn</a></li>
                </ul>
                <form class="navbar-form navbar-right" role="search">
                          <div class="form-group">
      <input type="text" class="form-control" placeholder="Search"/>
    </div>

                </form>
            </div>
        </div>
    </nav>

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

Updating in real-time through a dynamic jQuery request

Encountering difficulties in performing a Live update after a Live call. The event is successfully added to the dBase, but I am encountering issues with updating the contents of the div that has been changed. We are trying to display the confirmation withi ...

Conceal an entire div using CSS, especially if a portion of it remains unoccupied

Is there a way to conceal an entire division if a part of it is void? For instance, if "dd" is empty as indicated below, can I hide the entire class "test" so that the keyword Restrictions does not display either? I attempted .test dd:empty { display: none ...

Troubleshooting Dynamic Input Issue - Incorrect Appending Behaviour - Image Attached

I am working on a project that involves adding input fields dynamically using JavaScript. However, I've encountered an issue where the styling of the first input field is not applied correctly when it is clicked for the first time. You can see the dif ...

Uncover a one-of-a-kind identifier within the jQuery each() method

Is there a way to create a selector that can accurately refer to the current targeted DOM element (referred to as this) within an iteration of a jQuery each loop? For example, if the selector were #abc, .xyz and the HTML source was: <body> ...

Buttons aligned vertically alongside an input text field

I am trying to align two buttons vertically under an input text box with the middle aligned. This is what I have done so far: jQuery(document).ready(function($) { // Implementing bootstrap minus and plus plugin // Reference: http://jsfiddle.net/lael ...

The concealment of the container is ineffective when attempting to hide it until all cached images are

My website has a background and a main container. I wanted to hide the container until the entire page had loaded, so I included #cover{opacity:0} at the beginning of the page and $(window).load(function() { $('#cover').css('opacity&apo ...

Creating child rows with forms in Datatables

Currently, I am utilizing this particular example where I have a form embedded within the child rows. However, I have encountered an issue - the input from the child rows is not being submitted if the child rows are closed. Upon further examination, I noti ...

Resizable vector graphics with consistent border dimensions

I need a solution that maintains a constant line width while still making the SVG responsive. Here is the desired outcome: https://codepen.io/dudleystorey/pen/wMLBLK The example linked above achieves this using CSS, but I am looking to achieve the same r ...

What is the best way to ensure an input field and a button are aligned perfectly within the same div tag and of equal height?

During a recent HTML-CSS project, I encountered an issue where I struggled to ensure that two elements within a div tag were the same height. The elements in question were an input field and a button with an icon. Here is a snippet of the relevant HTML cod ...

Sending data to server using Ajax and jQuery

Hey there, experiencing a little hiccup in the back-end of my system when I try to submit my form. It keeps showing me an error saying Unidentified index: file1 . Can't seem to pinpoint where the issue lies in my code. Even though I'm no beginner ...

What's the best way to combine cells using HTML, CSS, and PHP?

Can anyone assist me with merging cells containing identical values in specific columns? <td style="text-align: center; font-size: 9.5px;">{{$endereco->quadra}}</td> <td style="text-align: center; font-s ...

Position the div element beside the image, rather than below it

I am having an issue with Bootstrap where the card I want to display on the right of an image is appearing below it instead. I attempted to use the display: inline-block property, but unfortunately, that did not solve the problem. I also explored other so ...

Prevent jQuery validation from passing with radio buttons

I am currently encountering an issue with a particular field in my form that is being validated by jquery. Here is the troublesome field: <label>Select an Account Type<</label><br> <input type="radio" name="accountType" value="1" ...

Changing the border color of a Bootstrap 5 button using custom CSS styling

I have been working on a page to control my amp using various JavaScript libraries. 1.) How can I change the blue border of a selected Bootstrap 5 button to a lighter green without using SCSS? Example: Repository (apologies for the mess, it's not t ...

CSS: "Cutting-edge" design. In what way?

I am seeking to replicate a design similar to that of Fantastical's website (https://flexibits.com/fantastical), where the edge of a screenshot extends beyond the page boundary. As the user resizes the window, more of the screenshot becomes visible. A ...

"Utilizing Google Closure Compiler to Optimize a jQuery Plugin

I've been experimenting with the Google Closure Compiler and attempting to compile the Facebox Plugin using the "Advanced" option. However, I encountered an error where the function was looking for "a.H". Has anyone successfully compiled jQuery plugi ...

React App Showing Scrollbar When Material UI AppBar is Present

I'm encountering a straightforward issue in my React application. How can I get rid of the scrollbar on my page? It seems like the problem arises from the height value I set to 100vh. However, upon removing the AppBar, the scrollbar disappears. Any su ...

What is the best way to determine the quantity of identical items in the django templating language?

My goal is to create a table that organizes items by type, all retrieved from my database. Currently, I can display the items and their corresponding types without any issues in a table format. However, I want to avoid repeating the same type multiple time ...

Personalize the md-tab component in Angular 2

I'm encountering an issue with styling the md-tab component in Angular 2. While I understand that Angular 2 Materials is currently under development, I am wondering if there is a way to customize it, such as removing the bottom-radius. Below is an exa ...

Use of number type input on mobile devices in HTML

My goal is to display the up/down arrows alongside an input element with type="number" in Chrome on Android. I've adjusted the CSS to set opacity=1, but unfortunately, they are not appearing. On desktop, however, they show up without any iss ...