Attempting to place the search bar within the navigation bar

Having trouble positioning a search bar in my nav bar, I'd like it to show on the right side without overlapping any other elements. Tried relative and absolute positioning with no success so far.

Any assistance would be greatly appreciated, thank you! :)

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

Codepen link - version= https://codepen.io/Teamkhaleesi/pen/gOoNJJy

@import url('https://fonts.googleapis.com/css2?family=Open+Sans&display=swap');
html,
body {
  margin: 0;
  padding: 0;
  height: auto;
  font-family: 'Poppins';
  box-sizing: border-box;
  background-color: rgb(236, 241, 236);
}

body {
  margin-bottom: 0;
  padding: 0;
}

.search-bar {
  float: right;
  width: 200px;
  height: 40px;
}

.search-bar .search-icon {
  position: absolute;
  right: 0px;
  /*adjust this*/
  top: 0px;
  /*adjust this*/
  background-color: red;
}

nav {
  width: 100%;
  height: 140px;
  background-color: #333;
  color: #fff;
  text-align: center;
}

nav p {
  font-family: 'poppins';
  color: white;
  font-size: 40px;
  line-height: 40px;
  padding-top: 2%;
  text-align: center;
}

nav ul {
  margin: 0px auto;
  display: inline-block;
}

nav ul li {
  float: left;
  list-style: none;
  position: relative;
}

nav ul li a {
  display: block;
  font-family: 'poppins';
  text-transform: uppercase;
  color: white;
  font-size: 20px;
  text-decoration: none;
  padding: 0px 30px;
}

nav ul li a:hover {
  color: black;
}

nav ul li ul {
  display: none;
  position: absolute;
  padding: 10px;
  background-color: rgb(215, 209, 209);
  border-radius: 1%;
  z-index: 1;
}

nav ul li:hover ul {
  display: block;
}

nav ul li ul li {
  width: 180px;
}

nav ul li ul li a {
  padding: 8px 10px;
  color: black;
}

nav ul li ul li a:hover {
  background-color: rgb(120, 118, 118);
  transition: ease-in-out 0.2s;
}
<nav>
  <p>Book PRESS</p>
  <ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">Books <i class="fa-solid fa-caret-down"></i></a>
      <ul>
        <li><a href="">Young Adult</a></li>
        <li><a href="">Adult</a></li>
        <li><a href="">Non-Fiction</a></li>
      </ul>
    </li>
    <li><a href="#">Authors <i class="fa-solid fa-caret-down"></i></a>

      <ul>
        <li><a href="">Our Authors</a></li>
        <li><a href="">Book Tours</a></li>
        <li><a href="">Events</a></li>
      </ul>
    </li>
    <li><a href="#">About Us <i class="fa-solid fa-caret-down"></i></a>
      <ul>
        <li><a href="">Our Team</a></li>
      </ul>
      <li><a href="#">News</a></li>
    </li>
    <li><a href="#">Contact Us <i class="fa-solid fa-caret-down"></i></a>
      <ul>
        <li><a href="">Submissions</a></li>
        <li><a href="">Permissions</a></li>
        <li><a href="">Translation</a></li>
        <li><a href="">Press</a></li>
        <li><a href="">Hiring</a></li>
        <li><a href="">Contact</a></li>
      </ul>
      <li class="search-bar">
        <form class="form"> <input type="text" name="Search" placeholder="Search"> <button type="submit"> </button> </form>
      </li>
    </li>


</nav>

Answer №1

After running a test on your code, it appears that the search bar is correctly positioned to the right. Unfortunately, I don't have sufficient reputation to leave comments, so I'm responding here instead.

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

Having difficulties retrieving the <td> id using jQuery

I am a beginner in the world of JavaScript and jQuery, and I am currently attempting to extract both the ID and the value of an element. Here is my initial AJAX request: $.ajax({ type: "POST", url: "Home/AddText", data: JSON.stringify({ te ...

Is it possible to determine if jQuery find returns true or false?

Snippet of HTML Code <div class="container1"> <div class="box1">Box 1</div> <div class="box2">Box 2</div> <div class="box3">Box 3</div> </div> <div clas ...

Cannot utilize Map within each loop

Below is the less code snippet: @threshold:{ a:50; b:200; }; @themes:{ a:red; b:blue; }; .mymixin(@name,@color,@thrshld){ //do-something } each(@themes,{ .mymixin(@key,@value,@threshold[@key]); }); Upon executing the code, an error message ...

Retrieve the rendered component color variables exclusively from the global color variable file

color_variables.css: [data-theme='default'] { --avatar_bg: #000; --avatar_text: #fff; --avatar_border: red; --button_bg: blue; --button_text: #fff; --button_border: darkblue; --modal_widget_bg: orange; --footer_bg: yellow; --foo ...

Is there a way to prevent the second ul from appearing?

Seeking assistance with navigation. When clicking on the "Athletics" tab in the provided link, the second ul displays. Is there a method to hide this second ul and have it only appear upon hovering? ...

Centering Images Using CSS Floats

I've got this HTML code featuring images and titles: <div class="container"> <div class="box"><a href="#" class="catname"><img src="image1.jpg" class="thumb"><p>Title 1</p></a></div> <div class="box" ...

Utilizing Vue.js: accessing a global value within a template string

I am working on a simple Vue.js application with the following structure: index.html (only the <body> for brevity) <div id="root"></div> main.js var settings = { title: 'My App', } new Vue({ el: '#root', tem ...

A messaging application powered by socket.io and the Express JS framework

I am currently learning Node.js and I am encountering an issue with using socket.id to identify logged in users on the client side using their email id and password. The verification process happens on the server side, and if successful, the user's so ...

The confusion surrounding navigation in Angular's single-page applications

I'm struggling to grasp how Angular handles routing in my single-page application. Here's my issue: When I type in the url: localhost:3000/streams/ I expect the 'streams' page to load. My understanding was this: My express serve ...

Steps to alter background image and adjust its height upon function activation

I am working on a search page with an advanced search option that only certain users can access. I need the height of my div to increase accordingly and also change the background image to a larger size when the advanced search is selected. How can I make ...

Creating a centered and beautifully styled picture with a specific maximum size using React

I recently completed the development of a new website, which can be viewed at Upon inspection of the website, it is evident that the photo is not centered and appears too large on mobile phones. Despite my efforts to align it using various methods outline ...

Vue 2.0: Exploring the Power of Directive Parameter Attributes

It has come to my attention that directive param attributes have been phased out in Vue.js 2.0. As a result, I am unable to use syntax like v-model="msg" number within an input tag. Are there alternative methods to achieve the same outcomes without relyi ...

Tips for preserving drop down selections when refreshing the page

I am currently working on a program with 2 drop-down menus and 2 buttons. My goal is to have the first button disabled and second enabled when both dropdowns are selected and the "start" button is clicked. Additionally, I want the dropdowns to be disabled ...

Launching npm using the command "npm run protractor" results in console errors being thrown upon completing the test

Recently, we made the decision to streamline the installation process of Protractor on local machines by specifying it in package.json rather than installing it individually with the -g flag. The addition we made looks something like this: "scripts": { ...

Sorting by number or date in indexedDB may lead to unexpected results due to the

I have set up an index in my database called time on the created_at field: var os = thisDB.createObjectStore(name, { keyPath : "id" }); os.createIndex("time", "created_at", {unique: false }); Instead of storing the time as a standard date format, I conv ...

Does the Android 4.3 Internet browser not support @font-face declarations?

After my Samsung Galaxy S3 phone recently updated from Android 4.1.3 to Android 4.3, I noticed that some of the websites I designed are not displaying the fonts correctly. These sites were tested on the Android internet browser and use @font-face. How can ...

Ways to retrieve keys from the json object below

Working on integrating handsontable with a php backend, I'm attempting to dynamically generate table column headers. This involves creating an array of column names that will be used in handsontable like so: colHeaders: ['ID', 'First&a ...

Rendering of @font-face on Windows 7 was executed flawlessly

I have been utilizing @font-face to implement custom fonts on a website. The custom font displays correctly in Firefox, IE, Safari, and Chrome on Mac. However, when viewed on Chrome in Windows 7, the text appears green at 10px instead of black or grey. ... ...

"Utilize JavaScript to structure JSON, eliminate redundant entries, and calculate the total number

I'm feeling a bit disoriented, as I have this dataset in json format with timestamps and ids arranged like so: [{ "date":"2016-11-18 19:20:42","id_pa":"7" },{ "date":"2016-11-18 19:04:55","id_pa":"5" },{ "date":"2016-11-19 20:53:42","id_pa":"7" ...

Preventing Duplicate Entries in Angular Data Posting

I am currently trying to submit a form to a PHP page that will then return a table of data. The process works perfectly fine if I do not include any parameters in the post request. However, as soon as I try to add parameters for the query, I encounter an n ...