Keeping everything aligned, my aim is to position the search bar and the logo side by side on the left-hand side and stretch the search bar all the way to the end

Looking to adjust the placement of the logo and search bar on the left side while extending the search bar further to the right. Struggling to get the desired layout? No worries, we've got you covered! Also need a join and log in button aligned to the right of everything. Having trouble positioning the submit button next to the search field? Check out this example for reference here

@import url('https://fonts.googleapis.com/css?family=Poppins');
body {
  font-family: 'Poppins';
}

header>div {
  padding: 0 25px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid lightgray;
}

nav {
  width: 600px;
}

nav ul {
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

nav a {
  text-decoration: none;
  color: black;
}

.blackHeart {
  width: 20px;
  margin-right: 1rem;
}

.searchmenu {
  padding-top: 12.5px;
  padding-bottom: 12.5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  width: 50px;
  margin-left: .3rem;
  display: right;
}

.topnav .search-container {
  float: right;
}

.topnav input[type=text] {
  padding: 6px;
  font-size: 17px;
  border: none;
}

.topnav .search-container button {
  float: right;
  padding: 6px;
  background: red;
  font-size: 17px;
  border: none;
  cursor: pointer;
  color: white;
}

.topnav .search-container button:hover {
  background: black;
}

.search {
  background-color: rgba(211, 211, 211, 0.463);
  float: right;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="./style.css">
  <title>Document</title>
</head>
<header>
  <div>
    <div>
      <img class="blackHeart" src="images/black-heart.png" alt="black heart" />
      <span> Nifty Penguin Magic </span>
    </div>
    <nav>
      <ul>
        <li><a href="#"> npm Enterprise </a></li>
        <li><a href="#"> Products </a></li>
        <li><a href="#"> Solutions </a></li>
        <li><a href="#"> Resources </a></li>
        <li><a href="#"< Docs </a></li>
        <li><a href="#"> Support </a></li>
      </ul>
    </nav>
  </div>

  <div class="searchmenu">
    <ul>
      <div>
        <img class="logo" src="images/npm-logo.png" alt="npm logo">
      </div>
      <div class="topnav">
        <div class="search-container">
          <form>
            <input type="text" placeholder="Search.." name="search" class="search">
            <button type="submit">Submit</button>
          </form>
        </div>
      </div>
      <div>
        <a href="#">Join Log In</a>
      </div>
    </ul>
  </div>
</header>

<body>

</body>

</html>

Answer №1

Are these changes working? I decided to remove all instances of float: right from the code and replaced them with flexbox instead.

@import url('https://fonts.googleapis.com/css?family=Poppins');
body {
  font-family: 'Poppins';
}

header>div {
  padding: 0 25px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid lightgray;
}

nav {
  width: 600px;
}

form {
  display: flex;
}

nav ul {
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

nav a {
  text-decoration: none;
  color: black;
}

.blackHeart {
  width: 20px;
  margin-right: 1rem;
}

.searchmenu {
  padding-top: 12.5px;
  padding-bottom: 12.5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  width: 50px;
  margin-left: .3rem;
  display: right;
}

.topnav, .searchContainer {
  width: 100%;
}

.topnav input[type=text] {
  padding: 6px;
  font-size: 17px;
  border: none;
}
...
        <a href="#">Join Log In</a>
      </div>
    </ul>
  </div>
</header>

<body>

</body>

</html>

Answer №2

It appears that using floats is causing the issue, and I have also updated your HTML and CSS for comparison.

@import url("https://fonts.googleapis.com/css?family=Poppins");
      * {
        padding: 0;
        margin: 0;
        box-sizing: border-box;
      }
      body {
        font-family: "Poppins";
      }

      header > .firstnav {
        padding: 12.5px 25px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 1px solid lightgray;
      }

      nav {
        width: 600px;
      }

      nav ul {
        list-style: none;
        display: flex;
        justify-content: space-between;
        align-items: center;
      }

      nav a {
        text-decoration: none;
        color: black;
      }

      .blackHeart {
        width: 20px;
        margin-right: 1rem;
      }

      .searchmenu {
        padding: 12.5px 25px;
        display: flex;
        align-items: center;
        justify-content: space-between;
      }

      .logo {
        width: 50px;
        margin-left: 0.3rem;
      }
      .searchmenu form {
        position: relative;
      }
      .searchmenu form svg {
        width: 33px;
        background: beige;
        padding: 7px;
        position: absolute;
        color: black;
        height: 34px;
        top: -1px;
        left: 29px;
      }

      .searchmenu input[type="text"] {
        padding: 6px 35px;
        font-size: 17px;
        border: none;
        background-color: rgba(211, 211, 211, 0.463);
        margin-left: 30px;
        width: 1050px;
      }

      .searchmenu button {
        padding: 6px;
        background: red;
        font-size: 17px;
        border: none;
        cursor: pointer;
        color: white;
      }

      .searchmenu ul li {
        list-style: none;
        padding: 5px 0;
      }
      .searchmenu ul li a {
        text-decoration: none;
        padding: 0 15px;
      }
      .searchmenu ul {
        display: flex;
      }
      .join {
        border: 1px solid grey;
      }

Here is your updated HTML:

<header>
      <div class="firstnav">
        <div>
          ...
    </header>

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

Interactive Div Updates Dropdown Selections Automatically

// function to add set of elements var ed = 1; function new_server() { ed++; var newDiv = $('#server div:first').clone(); newDiv.attr('id', ed); var delLink = '<a class="btn btn-danger" style="text-align:right;m ...

Leveraging the sibling combinator for altering the class of a sibling SVG element with the assistance of Material

I have created an SVG picture that I am trying to animate. Behind the elements I want to animate on mouse hover, I have added transparent rectangles. The hover effect works well on these elements as the cursor changes to pointer. However, when I attempt t ...

A div element springs forth into a new window and seamlessly transitions back to its original position with fresh content

Most of us are familiar with Gmail chat, where you can pop out the chat window into a new window with its content, and then pop it back in to its original position. However, I encountered an issue while working on replicating this functionality. While I w ...

Using HTML5 swipe.js with CSS3 transitions allows for smooth transitions between pages. Additionally, offscreen rendering and caching

I am currently developing an HTML5 magazine specifically designed for tablets and desktops utilizing swipe.js (). Everything is functioning smoothly, as I have arranged fullscreen list elements side by side on a single HTML page. The entire magazine is st ...

What is the best way to align an image in the middle of an image slider within a Bootstrap

Struggling to align the image properly in a Bootstrap 5 image slider carousel: https://i.sstatic.net/upPza.png <div id="carouselExampleIndicators" class="carousel slide" data-bs-ride="carousel"> <div class=&qu ...

CSS - a collection of hyperlinks to browse. the pseudo-element a:visited::before is not behaving as anticipated

Here's what I'm looking to achieve: http://codepen.io/anon/pen/KaLarE I want to make a list of links, each with a checkbox in front. Then, I want to be able to check the boxes for visited links. I attempted this approach, but unfortunately, it ...

Do we need to include href in the anchor tag?

Why am I unable to display the icon within the <anchor> element without using the href attribute? The icon only appears when I set the href attribute to "". Even if I manage to show the icon by adding href="", adjusting the size with width and height ...

Is there a way in AngularJS to set all radio buttons to false when one is chosen as true?

When I retrieve true/false string values from the database, I am unable to alter the data. The example I provided is simply a representation of the string values true or false that I receive from the database. My goal is to have a single radio button disp ...

How can I extract information exclusively from child nodes with Jsoup?

Currently, I am facing an issue with extracting first-level <li> elements from a <ul> element. Even though I attempt to retrieve only the first-level <li> elements using Jsoup selector or getElementsByTag, the nested <li> elements w ...

Place an element in relation to its initial position, ensuring that the x-coordinate is not set to 0

Is there a method to place an element in relation to its initial position, only excluding x=0 - meaning that the element is placed at its original vertical coordinate but sticks to the window's left edge? ...

Next.js encountered an issue: React.Children.only function was expecting to receive only one React element child, but received more

I have created a component named Nav located in the components directory. Here is the code for it: import Link from 'next/link'; const Nav = () => { return( <div> <Link href="/"> <a> Home </a> ...

Ensuring Smooth Alignment of CSS Divs

I am facing challenges with the compatibility of my CSS code for HTML checkboxes. In certain versions of Internet Explorer and when I insert the live HTML into my PowerPoint presentation, the center div overlaps with the left div causing the entire page to ...

How to toggle elements using CSS slide animations?

Is there a way to make a div slide in and out from the left to right when the user clicks on "clickthis"? Here is an example of CSS code: .container{width:100px; position:absolute; left:-70px;} .container .open{left:0px;} .button{display:block; top:0px; ...

Is it possible for a web server to transmit information without being prompted by the client?

I'm looking to create a web application for a tool that can run anywhere from a minute to a couple of hours. I want users to be able to initiate the tool's run directly from the webpage, and receive real-time status updates as the process progres ...

Incorporate New Material into DIV Using a Specific Class Identifier

I need to customize the default output of Wordpress menu using <?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>. My goal is to change the appearance of pages with submenus. Currently, pages with a submenu are fo ...

The height of scrollbars in the HTML section does not extend to full coverage

On my HTML webpage, I am facing an issue with the "left-section" scrollbar. It does not cover the entire height of the section. The scrollbar only appears when the window is resized small enough to reach "Link 18". Even then, the scrollbar does not scroll ...

CSS: Header overlapping navigation menu, disrupting hover effects

While working on my website, I noticed an issue with the div#top element covering the menu. As a result, you can only hover over a link when directly under the text. Does anyone have any suggestions on how to resolve this? ...

Ensuring that the two columns in a responsive grid have equal heights is essential for maintaining a

I am currently working on a responsive website with a main content area (.content-wrapper) and a sidebar area (.search-listing). My goal is to make sure that both columns have the same height. I attempted to achieve this using the following jQuery code: j ...

Instructions on how to change the color of specific text to red

Issue: While working on my testimonials page, I am facing a problem with displaying an "ADMIN" tag in red color instead of normal stars for one of the responses by an admin. I have tried various solutions like removing the ending p tag and adding quotes to ...

Ways to initiate a flip motion

Looking for a way to create a flip image effect when clicked by the user. Here is the code I have so far: let img = document.querySelector('img') let div; let click = 0; img.onclick=function(){ console.log(click) if(click %2 ==0){ d ...