user14192941
user14192941

Reputation:

Trying to position searchbar in nav

I made a nav bar, and I'm trying to add a search bar to it, but I can't seem to position it. I'd like to have the search bar show on the right side of the nav bar without overlapping any of the other elements. I tried relative and absolute position but nothing so far.

Any help is very much appreciated, thank you! :)

enter image description here

Here's the codepen - 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>

Upvotes: 0

Views: 182

Answers (1)

abubakarutar
abubakarutar

Reputation: 141

I've tested your code and it already seems to be positioning the search bar to the right (I don't have enough reputation to comment so I have to reply here sorry)

Upvotes: 1

Related Questions