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

I am trying to display my progress bar in a col-sm-6 format on screens larger than 546px, however, despite my attempts, I am not seeing any changes on the screen

Is there an alternative method if bootstrap is unable to handle this? I have used col-xs-6, but all I want is to display my progress bar in the image shown on small screens. Here is how I want to display my image on small screens. <div class="cont ...

Applying a translucent layer of color to a jpeg image to create a subtle background effect

I am attempting to create a semi-transparent, solid background color on top of an <img> tag, while still showing the original image underneath at the same ratio and size. Below is a snippet of the code I am working with (let me know if you need more ...

Consistent Row Heights for Dynamic Width Elements

I've relied on Chris Coyier's Equal Height Blocks in Rows jQuery script for various projects, and it has consistently delivered great results. However, this time I am facing a new challenge as I work on a responsive website with a fluid width ma ...

Several levels piled one on top of the other

I'm in the process of designing a section for a webpage using Bootstrap 3.0, and I want to layer three divs or sections on top of each other. The stacking order should be as follows: background "squares," footer, and foreground "squares" with images. ...

Transform this color matching game into an image matching game using JavaScript and jQuery

I have a color matching game that I would like to enhance by matching background-images instead of just background-colors. However, I am facing difficulties in making this change. For instance, instead of matching the color red with the text "red," I wan ...

Find the total sum of various spans

As a beginner in programming, I am facing a challenge that I cannot seem to solve. How can I retrieve the values of multiple spans with the same class? This is how the HTML code looks: <ul> <li> <input type="checkbox" value="30 ...

Position a div off-center using CSS styling

Currently, I am utilizing a flexbox to center a div inside another div, akin to a dialog window that pops up at the center of the screen when required. The functionality is sound, but aesthetically it would be more pleasing if the space above and below th ...

Can ChatGPT Service Error be resolved?

I tried using chatGPT to help me with my HTML code, but every time I opened it I received an error message saying "Failed to get service" Here is the code that I want to make work: <html> <head></head> <body> <script& ...

I'm struggling to make my div display inline

My div elements are not displaying inline, I'm thinking maybe I shouldn't use the nav and div structure like this. But starting over again seems like a lot of work. How can I fix this issue? Just so you know, I'm only on my 4th day of learn ...

encountered net::ERR_EMPTY_RESPONSE while attempting to locate a CSS file within an AngularJS directive

Every time my webpage attempts to access the css file from a directive, I encounter a net::ERR_EMPTY_RESPONSE. I have implemented door3's on-demand css feature, which allows for lazy loading of css files only when necessary. This feature works flawle ...

Incorporate web control's stylesheet into page with UpdatePanel registration

What is the most effective way to register a stylesheet only once on a page using a custom web control? Keep in mind that the page utilizes an UpdatePanel for asynchronous calls. I attempted placing the <link> tag in ScriptManager.RegisterClientScrip ...

Change the function from onLoad to onClick exclusively

I'm experiencing a particle explosion on my webpage due to this code. I connected the onClick function to a button in my HTML so it executes only when that specific button is clicked. However, the function automatically runs when I load the HTML and ...

Having trouble getting the JavaScript slider to animate

My code works perfectly in Codepen but when I try to implement it on my website, it shows as a static image. You can view the code here: https://codepen.io/anon/pen/zPMKpv I'm using the exact same code on my website located at: Does anyone have any ...

Having trouble with your website div not appearing correctly on Firefox?

I'm facing an issue with the display of a website (found here). The elements inside the div with the class name of .index_container are not appearing correctly in Firefox. Despite being present, they remain invisible. I've attempted to resolve th ...

The images are not clickable when trying to hyperlink them

I'm attempting to create a clickable image that will redirect users to another site when clicked. Here's the code I've tried: <div class="haus"> <a href="http://google.com"><img src="http://schwedenladen.de/wp-content/the ...

Toggle nested menu within another submenu

Looking for help with toggling menu items? I currently have a menu setup with 3 icons where clicking on an icon opens the dropdown-mobile UL under it. The goal is to toggle different submenu items when 'Main menu item' or 'sub-menu item&apos ...

Identify objects obstructed from camera view (hidden behind other objects) - Three.js version 71

I am working on triggering intersectObjects when a mesh is behind another mesh (to determine if the mesh is visible to the camera). Currently, I have found that intersectObjects is triggered when a mesh is both behind and in front of another mesh. Here i ...

On mobile devices, the alignment of text in Bootstrap doesn't appear as intended

I'm creating a portfolio website for showcasing my design projects from university. The text in the "my work" section is centered, but it seems misaligned with other elements like buttons when the window width is reduced. What could be the issue? Cod ...

Align the subtext to the right and center it vertically within a Bootstrap dropdown menu item

Is there a way to vertically align small captions on the right side of a dropdown menu, next to each item's text? The issue is that in the example below, the numbers are not properly aligned. https://i.stack.imgur.com/NZigW.png The numbers 123 and 1 ...

Unlocking the potential of data inputted in a JQuery Autocomplete form

Seeking assistance with extracting data from a form to utilize for additional purposes <form onsubmit="return false;"> Enter a School: <input id="schoolsearch" type="text" /> <INPUT TYPE=SUBMIT VALUE="GO"> </form> I am struggling ...