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

Breaking apart a string and mapping it to specific fields

My issue is relatively straightforward. Upon loading my page, a long string representing an address is generated. For example: 101, Dalmations Avenue, Miami, Florida, USA, 908343 With the help of jQuery, I can split the string using: var address = sel.o ...

Troubleshooting: ReactJS CSS Class Issue

I'm fairly new to working with ReactJS and I've encountered an issue while trying to create a class for a specific form. Below is the code I've written: import React, { Component, PropTypes } from 'react'; import s from './s ...

I'm a bit uncertain about the best placement for my progress bar component during the API call

Trying to grasp material ui I managed to implement the progress bar. Struggling with loading it until my data is fully loaded. Uncertain about where to place my progress bar component. Could you guide me on how to resolve this issue during API calls, so I ...

Set a variable to represent a color for the background styling in CSS

My goal is to create an application that allows users to change the background color of a button and then copy the CSS code with the new background color from the <style> tags. To achieve this, I am utilizing a color picker tool from . I believe I ...

Is there a way I can implement a user-friendly playlist feature in my object-oriented HTML5 JS audio player that allows users

I have created a functional audio player using HTML5 and Javascript, along with some basic CSS. However, I am looking to enhance it by adding a clickable playlist feature. I want the name of the currently playing audio track to be displayed, and users shou ...

Turn off base64 encoding for background URLs in the Minify package

When I use the minify tool to compress my js and css files, I noticed that the files containing background:url(...) statements actually increased in size. This happened because the urls were encoded to base64. I tried to disable this base64 encoding featu ...

Lose the scrollbar but still let me scroll using the mouse wheel or my finger on the fullscreen menu

I am currently working on a fullscreen menu design. However, when the menu appears, some elements are not visible unless I apply the overflow-y: scroll property to the menu. But I don't like the appearance of the additional scrollbar that comes with i ...

Storing Unique Characters in the Database

Currently, I am utilizing a combination of HTML and PHP for my website, but I have encountered an issue when saving content in a textarea. Whenever I incorporate a different font with special characters like ' and ", it saves as � (a black dia ...

Utilize the `addEventListener` and `removeEventListener` functions on the menu to

Why is my mobile menu not functioning correctly? The submenu should open on the first click and redirect to the parent URL on the second click, which works fine. However, when the window width increases to 768px or more, the submenu should appear on hover ...

Focusing on the combination of Phonegap, Angular JS, and Onsen for app development

We are working on developing an app using PhoneGap, Angular JS, and Onsen. One issue we are facing is that we are unable to center the header in a modal. The code snippet is provided below: <ons-modal var="modalVariable"> <ons-navigator var"de ...

Showing identification on the drop-down list

Within my dropdown menu setup, I am aiming to achieve a specific functionality. When the user clicks on sub menu, I want the title of sub menu to display in the Menu space as illustrated below. What steps can be taken to accomplish this? UPDATE: After fu ...

"Border-radius becomes less prominent on pointer interaction in Chrome and Safari due to WebKit's behavior

Having an issue with a list inside a div. The problem arises when there is a div containing a list, which limits the visibility of items for users. If the limit is exceeded, a scroll bar appears inside the div to allow users to see more items. Additionally ...

Add CSS styling to a single form

When working on a larger project, the goal is to reduce the size of various elements within a form named quickpost-form <div id="qp-form"> Specific elements in the form require a smaller font size such as text, input, input-group, and tex ...

Apply a specific style conditionally using Angular's ng-repeat directive

Currently, I am utilizing ng-repeat to iterate through a list of divs and manually adding items to the JSON that is rendering these divs. My goal is to position the last div that I add in the JSON at the location where the mouse cursor is, while keeping th ...

Controlling the page scroll when adding data using jQuery

I am encountering an issue with a webpage that displays around 20 pictures in separate divs stacked vertically. Below these 20 pictures, there is a "show more" button that, when clicked, loads another set of 20 pictures and appends them to the existing dat ...

Issues encountered when using Vue Transition in conjunction with v-autocomplete

Attempting to conditionally display or hide a selection text field using Vue's Transition feature, but experiencing an issue where the text field appears and disappears without any transition effect. <template> <Transition v-if="is ...

In Google Chrome, the :after element on the left is cleared, while other browsers do not

In an effort to create a button using background images in the :before and :after pseudo-selectors for cross-browser compatibility, an issue arose where only Chrome did not display it correctly (Safari results were unknown). HTML: <div class="btn-cont ...

Having Trouble Operating Virtual Tour in Flash

I recently used a third-party software to create a virtual tour for my client's website. The virtual tour works perfectly fine on its own, as you can see here: However, when I tried to include the virtual_tour.html page on the index page of the websi ...

What strategies can I use to reduce duplication in my HTML and JavaScript code?

Struggling with messy HTML and JS code? If you're using Bootstrap-3 and jQuery-1.11.0, dealing with dropdowns might be tricky. Especially when it comes to switching icons based on the dropdown state and ensuring only one dropdown is open at a time. Is ...

The "else" statement is never being executed

Trying to create a form where users enter their first name, last name, and city. If any input is empty or contains numbers, a message should appear requesting to fill out all boxes without numbers. Otherwise, display a personalized quote using the input in ...