The right-aligned navigation bar elegantly shifts downward when it exceeds the screen width

I've been struggling to create a Right Aligned Navigation Bar with a search bar and a login icon that stay in one row on the page. No matter how I try, it keeps jumping down instead of aligning properly. Here is an image of what I'm trying to achieve: Here

nav{
    display: flex;
    justify-content: space-between;
    background-color: antiquewhite;
}

ul {
    display: flex;
    align-items: center;
    list-style: none;
    margin: 0;
    padding: 0;
}

ul li {
    margin-right: 20px;
    float: left;
}

form {
    display: flex;
    align-items: center;
    margin: 0 20px;
}

form input {
    padding: 5px;
    border: 1px solid #ccc;
    border-radius: 5px;
}
.right{
    display: flex;
    align-items: center;
}
.searchbar{
    margin-right: auto;
}

a.login-link {
    display: flex;
    align-items: center;
    margin-left: auto;
}

img.login-icon {
    width: 20px;
    height: 20px;
    margin-right: 20px;
}
img.logo {
    width: 230px;
    height: auto;
    margin-right: 20px;

}
 <div class="nav">
      <nav>
          <ul>
              <li><a href="index.php"><img class="logo"src="Snooker Logo.png" alt="Logo"></a></li>        
              <li><a href="index.php"><h4>Home</h4></li></a>
              <li><a href="bookingstatus"><h4>Booking Status</h4></li></a>                                
              <li><a href="paymentfile"><h4>Payment</h4></li></a>
              <li><a href="bookingfile"><h4>Booking</h4></li></a>             
          </ul>
          <div class="right">
              <div class="searchbar">
                  <form> 
                      <input type="search" placeholder="Search for an event you want">
                  </form>
              </div>
              <a class="login-link" href="#login">
                  <img class="login-icon" src="loginiconsnew.png" alt="Login">
              </a>
          </div>
      </nav>
  </div>

I need the navigation bar to be horizontal with the search bar and login icon aligned to the right-hand side.

Answer №1

nav {
        display: flex;
        justify-content: space-between;
        align-items: center;
        background-color: antiquewhite;
    }

    ul {
        display: flex;
        align-items: center;
        list-style: none;
        margin: 0;
        padding: 0;
    }

    ul li {
        margin-right: 20px;
    }

    form {
        display: flex;
        align-items: center;
        margin: 0 20px;
    }

    form input {
        padding: 5px;
        border: 1px solid #ccc;
        border-radius: 5px;
    }

    .right {
        display: flex;
        align-items: center;
    }

    .searchbar {
        margin-right: auto;
    }

    a.login-link {
        display: flex;
        align-items: center;
        margin-left: auto;
    }

    img.login-icon {
        width: 20px;
        height: 20px;
        margin-right: 20px;
    }

    img.logo {
        width: 230px;
        height: auto;
        margin-right: 20px;

    }

Implement the CSS code above by eliminating the float property for it to function correctly according to your requirements on my computer.

https://i.stack.imgur.com/DsErg.png

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

Issues encountered with integrating external jQuery/JavaScript functions with Wordpress child theme template

After creating a custom template in my WordPress child theme, I added a link to the Bootstrap v3.0.3 .js file stored on my site. While the popup modal is functioning properly, the jQuery tabs seem to be having some issues. Although they are being display ...

Running a series of functions consecutively with JQUERY

Currently, I am facing an issue with using an ajax method .load to replace the content of a div. The library I am working with does not allow me to replace the content of a div as some functions continue to run in the background. To overcome this challeng ...

Stable navigation bar implemented with a grid design

I'm struggling with creating Navbars in Grid Layout. https://codepen.io/Aeshtray/pen/BdqeZL For mobile view, I want the Navbar to be fixed horizontally (as currently coded), but once reaching a width of 500px, I need it to become vertically fixed on ...

Troubleshooting: JQuery - Applying CSS to dynamically generated elements

I used JQuery to dynamically generate a table, but I'm having trouble applying CSS to the columns. You can see an example at this Codepen link here. Specifically, I need to set the width of the first column to 100px. Could someone please assist me wi ...

Menu bar placed atop a carousel

I am currently in the process of developing a website and I have encountered an issue with the navigation bar. I have a slider that I would like to appear below the navbar but the navbar is pushing it down instead. Ideally, I want the navbar to be transpar ...

Modifying Row Color in Bootstrap 3: A Step-by-Step Guide

I'm trying to customize the background color of alternating rows in a Bootstrap 3 grid. I attempted to use CSS and add it to the class within the div, but unfortunately, the color isn't changing as expected. Below is the CSS code I used: .row-b ...

What is the best way to retrieve a particular value from a database using PHP?

$sql="Select chanceNo From gm_gacha_token1 where token_code='$mytoken'"; $result=mysql_query($sql); $count=mysql_num_rows($result); Language: PHP I am attempting to retrieve a single value of `chanceNo. Is there a way to get this value and stor ...

Efficiently showcase connected pages in real-time

I've come across an issue with my express app. Whenever a navigation link (such as Home, Home1, or Home2) is clicked, an error occurs. However, if I manually type in http://localhost:8001/home1, it displays home1.html without any issues. What I' ...

"Creating a duplicate of an element by utilizing the `next`

I have a dilemma involving two divs within a section of my project - one div is dynamically created while the other exists statically. My goal is to transfer the non-dynamically created div into the one that is generated dynamically. let adContainer = $ ...

Tips for maintaining the footer at the bottom of the page regardless of the screen size

In my current project, I am dealing with several web pages. For each page, I have arranged three div tags: Header Body (content) Footer The issue arises when it comes to the body div tag, which houses the main content of a page such as forms and descrip ...

Is there a way to occupy the extra space while working with an inline unordered list?

Using this unique CSS code, I've managed to give my unordered lists a touch of elegance: ul, li { padding: 0px; margin-left: 0px; margin-bottom: 0px; display: inline; } li { border: solid 1px #333333; margin-right: 5px; padding: 2p ...

Demonstrating various elements within an application using Vue3

I created two components and attempted to display them in a Vue 3 application. Here is my HTML code: <div id="app"> <image_preview> URL: [[image]] </image_preview> <file_uploader> Counter:[[coun ...

placed three blocks inside the table cell

Is there a way to align three blocks in the table-cell layout so that p1 is at the top, p2 is at the bottom, and p3 is in the middle? Here is the corresponding HTML: <div id="table"> <div id="row"> <div id= ...

The `.append()` function includes HTML content as plain text

I am using JavaScript to dynamically add HTML elements to my webpages. I have created a loop that iterates through all the projects, each containing multiple pictures. The first step involves generating the project title and adding it within a div element ...

jQuery image resizing for elements

I have successfully adjusted the images in the gallery to display one per row for horizontal orientation and two per row for vertical orientation. Now, I am facing a challenge in making the images scalable so they can resize dynamically with the window. A ...

What is causing all three boxes to shift when I'm attempting to move just one of them?

Seeking assistance with a problem I'm encountering. As I work on creating my website, I've run into an issue where trying to move one of the three individual boxes (as shown in the image) causes all three of them to shift together. You can view t ...

Choosing nested elements using CSS

Looking to target a specific element within a shared class, I'm struggling to find the right method to pinpoint the exact entry of this element. What I need to do is hide the current photo (pic2.jpg) and replace it with another image (pic3.jpg) in the ...

Changing text color with JQuery animation

Is there a way to animate text color using jQuery/jQuery UI? I want the text color to change from #000 to #F00 when an event is triggered, then fade back to #000 over 3 seconds. I attempted using effect("highlight", {}, 3000) with the highlight effect, bu ...

Utilize CSS to ensure divs display inline-block, but stack them only if they overlap

Below are the div elements I have: .parent { padding: 10px; background: grey; } .child { background: green; display: block; position: relative; width: 50px; } .stacked { left: 0px; } .three { left: 200px; } <div class="parent"&g ...

Tips for adjusting a web address provided by a user

I have a JavaScript code that prompts the user to input a URL and then appends it to a div. The code is working fine, but now I am trying to add functionality to edit the entered URL by changing the width and height of any iframes before appending them. ...