Is there a way to place my searchbox in the top right corner of the page?

I am currently working on creating a search function for my list of products. However, I have encountered an issue where the searchBox is not appearing in the top right corner as intended. Despite trying various solutions, I have been unsuccessful in moving it to the correct position next to the logo in the top right corner.

Below is the code for my search function:

function Navbar() {
  const [inputText, setInputText] = useState("");
  let inputHandler = (e) => {
    //convert input text to lower case
    var lowerCase = e.target.value.toLowerCase();
    setInputText(lowerCase);
  };
  return (
    <div className="navbar">
      <div className="logo">Shop</div>
      <div className="searchBox">
        <Product input={inputText} />
        <TextField
          id="outlined-basic"
          onChange={inputHandler}
          variant="outlined"
          label="Search"
        ></TextField>
      </div>
    </div>
  );
}

export default Navbar;

Here is the CSS code for styling this component:

.navbar {
  width: 100%;
  height: 50px;
  background-color: rgb(32, 32, 32);

  .logo {
    color: aqua;
    font-size: 1.8rem;
    font-family: "Orbitron", sans-serif;
    line-height: 40px;
    margin-left: 20px;
  }

   .searchBox {
    color: aqua;
    font-size: 1.8rem;
    height: 1%;
    width: 100%;
    font-family: "Orbitron", sans-serif;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}

Answer №1

You could experiment with using display: flex, justify-content: space-between, and setting width to 100% for the .navbar class. Additionally, consider removing the width: 100% property from the .searchBox class.

Answer №2

Here is a suggestion for you to try out!

.navbar {
      width: 100%;
      height: 50px;
      background-color: rgb(32, 32, 32);
      display: flex;
      align-items: center;
      justify-content: space-between;

      .logo {
        color: aqua;
        font-size: 1.8rem;
        font-family: "Orbitron", sans-serif;
        line-height: 40px;
        margin-left: 20px;
      }

       .searchBox {
        color: aqua;
        font-size: 1.8rem;
        height: 1%;
        font-family: "Orbitron", sans-serif;
        display: flex;
        align-items: center;
      }
    }

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

Struggling to keep text aligned to the left?

Check out the image at in my jsfiddle. It remains fixed in its position regardless of the screen width. However, the adjacent text does not behave in the same way. I aim to have the text positioned DIRECTLY next to the icon without any movement even if ...

Tips for displaying and sorting two requests within one console

I am currently working on a project to display both folders and subfolders, but only the folders are visible at the moment. function getParserTypes (types, subject) { return types.map((type) => { return { id: type.entry.id, name: type. ...

Exciting news ahead with swr, "Make sure to have fallback data ready when utilizing suspense in SSR."

I am attempting to incorporate React Suspense into a Next.js project My application is set up for client-side rendering only, without server-side rendering While Suspense is functioning properly, I have encountered the following error: Fallback data is ...

Sequence of promises: The parent promise does not wait for the child promise to be executed before moving on

I am retrieving data from a particular mongoDB collection. Within that response, I obtain the ID associated with another collection's data and merge it into one cohesive object. Take a look at my code snippet below. It seems like it's not waitin ...

Incorporating various language URLs in Next.js using next-i18n-next functionality

Thinking about using the next-i18next internationalization library. Check out next-i18next on GitHub Curious about how to change the language in the path of my URL. For example: /about-us /over-ons -> takes you to the Dutch version of the about us p ...

The functionality of react-infinite-scroll does not seem to be functioning properly when used within

Currently, I am utilizing the react-infinite-scroll-component to paginate comments for a specific post. Within the comment section, there is a button that triggers a drawer to display the paginated comments. However, the issue lies in the fact that the "ne ...

How can I securely save a user's login information using ExtJS without saving it multiple times?

Currently, I am utilizing Ext.Ajax.request() to access a PHP page that provides user-specific information during the login process. In order to store variables such as cookies and session information in ExtJS, I have created a model with necessary fields a ...

After a period of time since the server has been initialized, the function req.isAuthenticated() no

In my Node.js routes.js file, I have a function implemented to check if a request is isAuthenticated before serving it: function isLoggedIn(req, res, next) { if (req.isAuthenticated()) { console.log('Session Expiry '+req.session.cook ...

What is the process for extracting an object from an array?

As a newcomer to jQuery, I've encountered an issue that has me stuck. My problem lies in accessing an array within an object. Here's the structure of my object as shown during debugging: cache:object 0001-:Array[2] 0:value1, ...

React - Dynamically import file path for PDF document

Initially, the page will send an http request to an API The API will then respond with an object containing a path: ./assets/sample.pdf I am trying to extract the urlPdf from import urlPdf from response.path Any suggestions on how I can achieve this? ...

Issue with CSS in Internet Explorer 7

CSS CODE: .search { float: left; width: 100%; display: block; } .search ul.tabs { height: 23px; margin-top: 50px; padding: 0px; } /* FF ONLY */ .search ul.tabs, x:-moz-any-link { height: 26px; margin-top: 50px; padding: 0px; } .search ul.tabs ...

Guide to incorporating the useEffect hook within a React Native View

I am trying to use useEffect within a return statement (inside a Text element nested inside multiple View elements), and my understanding is that I need to use "{...}" syntax to indicate that the code written is actual JavaScript. However, when I implement ...

Update the styling of each div element within a designated list

Looking for a way to assist my colorblind friend, I am attempting to write a script. This is the layout of the page he is on: <div class="message-pane-wrapper candy-has-subject"> <ul class="message-pane"> <li><div style=" ...

Error-free ngClick doesn't trigger AngularJS controller method

I am struggling to trigger the removePlayer(playerId) method upon clicking a button. However, it seems that the method is not being called, as I have placed a console.log() statement at the top and the console remains empty. This situation has left me puz ...

Encountering unidentified data leading to the error message "Query data must be defined"

Currently, I'm utilizing Next.js to develop a project for my portfolio. In order to manage the API, I decided to implement both Tanstack query and Axios. The issue arises when attempting to retrieve the data as an error surfaces. Oddly enough, while ...

The css cropping issue with sprite image is not being resolved

I'm currently working on creating a sprite image for the bottom links on our media page, but I seem to be having trouble getting the image to crop correctly. Can anyone point out where I may be making a mistake? CSS .footer{ position:absolute; ...

Choosing bookmarkable views in Angular 5 without using routes

I'm currently working on a unique Angular 5 application that deviates from the standard use of routes. Instead, we have our own custom menu structure for selecting views. However, we still want to be able to provide bookmarkable URLs that open specifi ...

The React useEffect feature seems to be updating just one value

I am struggling to find a solution to this issue, even though I believe there is likely a simple explanation. I have two API calls, getNarrativeReferences and getNarrativeHeaders, that return values for two separate arrays in searchState. However, upon pag ...

Neglecting to utilize the document object within a React component results in the error "document is not defined."

I am utilizing browser detection code within a React component import React, { useState } from 'react' const BrowserDetectionComponent = ({props}) => { const isIE = document.documentMode; return ( <div> Custom browser s ...

Assigning arbitrary hidden form data from dropdown selection

Would like to assign Layers Value as one of the following: GFS Meteogram 3day std or WRF 20 Global Meteogram 3day Std depending on the option selected from the dropdown menu <div><select id="myselect" class="productViewerParameter" name=" ...