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

Executing window.open from Html.Actionlink in ASP.NET MVC 4

Here is the code block I am working with: @foreach (System.Data.DataRow drEquipment in Model.EquipmentList.Rows) { <tr> <td valign="top">@drEquipment["ColumnName"]<br /></td> <td valign="to ...

Determining the pageY value of a div element with overflow-y styling

Currently, I have implemented a script that tracks the mouse's position upon hover. My goal is to integrate this script within a div that has overflow-y: scroll The script currently utilizes pageY which identifies the position relative to the windo ...

Why is the complete object not being saved in the mongoose subdocument array?

I encountered a problem with my two nested schemas, where one is inside the other as an array. Even though I tried to push into the array and save the subdocument, it didn't save correctly. The saved object only includes its _id without any other fiel ...

Encountering a hiccup while trying to retrieve information from a JSON

I am currently working on a Jquery Drop Upload form and everything is functioning well. However, I am encountering an error when trying to retrieve data from the database using JSON. I'm not sure why this error is occurring, so please see below for mo ...

Is there a conflict between bootstrap.min.JS and chart.min.js?

I have been working on developing an admin page for customer support and I recently added a visually appealing chart to display some data on the home screen. The chart integration was successful, but when I introduced tab panes to the page and refreshed ...

The process of reversing an array is not fully completing due to the pop method being used within a loop

Note: I've been immersed in code for hours now and have reached a stage where I'm starting to doubt the spelling of every word or question if I have dyslexia. Despite this, I know this should be a simple question. I want to create a basic functi ...

Guide to setting up and launching a JavaScript/Vue GitHub repository on your local machine

I have a cloned app located here: cvss-v4-calculator that I want to run locally for debugging with VS Code or a similar tool. However, I'm encountering difficulties in setting it up. I've been attempting to run this as a web page using node.js, b ...

The Sizzle.js error, "Uncaught TypeError: undefined (reading 'expr')," is causing some trouble

$.expr[':'].containsCaseInsensitive = function (n, i, m) { return jQuery(n).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0; }; .expr is not recognized. To ensure it's defined, I included a CDN link below: <script src=&qu ...

New Line Styling in ReactNative Text

My goal is to create a column of 3 Texts with icons aligned vertically https://i.sstatic.net/BWXiL.jpg I'd like to add some top margin to the expo icons so they align next to each text element Also, how can I align the next line in the text with th ...

Mysterious data organization - transform into an object

As I interact with an API, there is a value that I cannot quite pinpoint. My goal is to transform this string into a JavaScript object, but the process seems complex and confusing. Does anyone have insight on what this data represents and how it can be co ...

Icon not appearing for push notifications on PWA using Firebase in ReactJS

I have successfully developed a PWA application using ReactJS and integrated Firebase Cloud Messaging for push notifications on devices. After installing my PWA on my Android phone, I am able to receive the correct push notifications. However, I am facing ...

Implement a click event listener in React.js

How can I implement a callback function for button clicks in my TypeScript code? This is the code snippet: export enum PAYMENT_METHOD { online, offline, } interface Props { paymentMethod: PAYMENT_METHOD; togglePaymentMethod: (paymentMethod: PAYM ...

What is the best way to include arrays in VueJS?

Currently, I am working with two arrays in my Vue application. The first array called desserts lists all the desserts that I have. The second array, moreDesserts, displays checkboxes with values. When a user selects a checkbox, the value is added to the se ...

Objects that are included into an array will end up with an undefined value

Currently, I am in the process of coding a command for my Discord bot that involves adding items to an array of objects stored within a JSON file. To achieve this functionality, I have implemented the following code snippet: let rawdata = fs.readFileSync(& ...

Using Angular to display asynchronous data with ngIf and observables

In cases where the data is not ready, I prefer to display a loader without sending multiple requests. To achieve this, I utilize the as operator for request reuse. <div class="loading-overlay" *ngIf="this.indicatorService.loadingIndicators[this?.indic ...

"Enhance your slider experience with React Alice Carousel: place dot controls directly over images for

I am currently working with react-alice-carousel and I'm looking to adjust the placement of the dot controllers on the slider. Instead of their current position, which you can see in this image (https://i.sstatic.net/mi6eD.png), I want them to be loca ...

The server encountered a 500 Internal Server Error because it could not read the 'username' property of an undefined object

When attempting to register a user in a mongodb database using express, a POST call was made to localhost:3000/users/register The request body included: { "firstName": "Jason", "lastName": "Watmore", "username": "jason", "email": "<a ...

Exploring the intricacies of using jquery text() with HTML Entities

I am having difficulty grasping the intricacies of the jquery text() function when used with HTML Entities. It appears that the text() function converts special HTML Entities back to regular characters. I am particularly uncertain about the behavior of thi ...

Mastering the onKeyPress event for Material UI text fields: A step-by-step guide

I have a TextField component from Material UI as shown below: <TextField id="todo-textarea" label="Enter new todo" placeholder="ToDo" onChange={this.props.toDoOnChange} onKeyPress={(ev) => { ...

Automatically include the date as a column heading along with name and ID

I recently came across a guide on how to dynamically add dates as column headers in a table. However, I encountered an issue where I couldn't add new columns for 'Name', 'Age', and 'Section' before the dynamically generat ...