What are the best ways to position elements within a material-ui App Bar?

My goal is to align the items in my navbar similar to this layout (replacing 'Buy on App Store' with a Search Box):

https://i.sstatic.net/4NOhU.png

I'm drawing inspiration from this material-ui component: https://material-ui.com/components/app-bar/#SearchAppBar.js

However, my current issue is that all of my items are clustered to the left instead of being aligned sensibly:

https://i.sstatic.net/sbgdN.png

How can I achieve proper alignment for my items? Could it be something inherited by my component? It directly imports into App.js without any parent components.

Below is my code snippet:

import React from 'react';
import AppBar from '@material-ui/core/AppBar'
import Toolbar from '@material-ui/core/Toolbar'
import Typography from '@material-ui/core/Typography'
import InputBase from '@material-ui/core/InputBase';
import { fade, makeStyles } from '@material-ui/core/styles';
import SearchIcon from '@material-ui/icons/Search';

const useStyles = makeStyles(theme => ({
    // Styles removed for brevity
}));

const Navbar = (props) => {
    const classes = useStyles();
    return (
        <div className={classes.root}>
            <AppBar position="static">
                <Toolbar>
                    <Typography variant="h6" noWrap>
                        MyApp
                    </Typography>
                    <div className={classes.search}>
                        <div className={classes.searchIcon}>
                            <SearchIcon />
                        </div>
                        <InputBase
                            placeholder="Search…"
                            classes={{
                                root: classes.inputRoot,
                                input: classes.inputInput,
                            }}
                            inputProps={{ 'aria-label': 'search' }}
                        />
                    </div>
                </Toolbar>
            </AppBar>
        </div>
    )
}

edit:

After removing { links }, as suggested in a comment, I still face the same alignment issue:

https://i.sstatic.net/GycI4.png

edit2:

Interestingly, removing the <Link> elements resolves the misplacement of my search box. Is there a reason behind this behavior? My challenge now is ensuring that the element directs users to the home page when clicking on the title.

Answer №1

To enhance the layout, I recommend incorporating a div container as shown below:

<div class="wrapper">
  <div class="header">
  </div>
  <div class="content">
  </div>
</div>
.wrapper {
  display: flex;
  align-items: space-around
}

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

Ways to customize hover color of Bootstrap 5 Dropdown menu

I'm having trouble modifying the hover color for a dropdown menu using Bootstrap 5. I'm unsure of the correct method to achieve this. The desired outcome is as follows: However, at the moment it appears like this: Apologies for the oversight, h ...

using Angular and RxJS to filter out an element from an array

One of the functions in my service is a delete function. This function calls an API that returns either true or false. If the response is true, I then proceed to find the index of the item in my array, splice it out, and return the updated array. Here&apos ...

Using Javascript to create a radio button group

Is there a way to trigger an alert message when all radio buttons are checked as 'no'? I currently am only able to check each radio button individually. //The method I currently know $('#attraction1').change( function(){ if ($(this ...

The Angular2 application successfully loads on the first attempt, but encounters an error when attempting hot-reloading, displaying the message "The selector 'app' does not correspond to any

SOLVED: The issue I encountered was related to my package.json. I discovered that it was an outdated version missing some of the necessary scripts and dependencies, unlike the one I referenced in my post. Oddly enough, I was still able to run the scripts a ...

Linked to various listviews, numerous flat buttons can be found. But how can we make the unselected buttons appear greyed out and unfocused

I am currently working on an app design that includes 3 flat buttons placed in a row. The first button is selected by default and displays a listView widget. The other two buttons should be greyed out until clicked, at which point they will show another ...

Accessing a precise div element in a webpage

Currently, I am utilizing Vue.js and Nuxt for my web development. One issue I am facing is related to anchors. Specifically, when I navigate to mysite.com/page1#section1, I want the page to scroll to section1. In my code, I have the following snippet: < ...

Sending a hook or function to a nested component

What is the best practice for updating state in React using Hooks? Option 1: This approach seems more traditional to me function App() { const [input, setInput] = useState(''); const onInputChange = (event) => { setInput(event.target ...

Unique Font Awesome Stylesheets

I'm facing a challenge with using Font Awesome to design my form. The FA icon comes pre-filled with color, but when I try to apply a specific color, it gets applied to the entire icon. Is there a way to work around this issue? Alternatively, should I ...

Transmitting information from Angular to Laravel

Hey, I'm facing a challenge once again. Currently, I am working on creating a to-do list application using Laravel and Angular. While I can successfully retrieve data from the database through the Laravel and Angular controllers, I'm encountering ...

React effortlessly showcases unprocessed JSON information following a query sent to an Express server

Looking to set up my react js with backend using react-routes. However, I've realized that when making an API request, I receive raw JSON data, which could potentially be a security risk. I came across a post where someone mentioned: "If your user a ...

Display a div element within a JavaScript alert

I have implemented a jQuery script for my menu links on an index.php page. Specifically, when the user clicks on the 'Info' menu item, it loads sectionInfo.html into the index.php page. This section contains a short form that may trigger an alert ...

Can someone explain the process of adding a JavaScript state variable from one React component so that it can be utilized in other components?

In my Home.js component, I handle user sign up to the API and login. After receiving the token from the authorization header in the response, I save it in the state variable 'token'. This token is crucial for accessing the API in other component ...

The transparent background causes the vertical menu to malfunction on IE8

This is the first website I am working on: www.olgoya.com The issue I am facing is that all major browsers, except IE8, display the submenu even when the mouse hovers over the 'portfolio' item. Upon investigation, I found that the problem lies w ...

What is the best way to ensure the box div is centered responsively?

Here is the code for my HTML file: body { background-color: rgb(231, 59, 59); font-family: "Alata"; font-size: 20px; margin: 30px; } h1 { margin-top: 100px; color: #202124; text-align: center; } .box { width: 1000px; } input { positi ...

Avoid using background images in HTML/CSS

I'm struggling to get my background image to show up despite trying various approaches. Any suggestions on how to fix this issue? ...

Interactive scrolling bar chart created with D3.js

Let's take a look at a simple bar chart: var margin = {top: 20, right: 20, bottom: 30, left: 50}; var xLPU=d3.scale.ordinal(); var yLPU=d3.scale.linear(); var xLPUAxis = d3.svg.axis() .scale(xLPU) .orient("bottom"); var yLPUAxis = d3.svg.axi ...

Automatically adjusting input box size and position in real-time

I am working on a form that includes a button and an input field. When the user clicks on the button "ADD MORE FIELDS," I want to dynamically generate a new input box. Although I have tried using code from this jsfiddle link and it works, my goal is to ach ...

Switching up the image using a dropdown selection menu

I am struggling with updating an image based on the selection made in a dropdown menu. I am quite new to javascript, so I believe there might be a simple issue that I am overlooking. Here is my attempt at doing this: JS: <script type="text/javascript" ...

What are some ways to handle component state within Next.js?

I need help creating a component that will monitor and update the text entered by the user in an input field, triggering a method when the text changes. My initial plan was to store the input's value in state, but I am encountering an issue with this ...

The slideUp and slideDown functions are not functioning properly

Whenever a user clicks on image-exp, I want description-exp to slide down while other description-exp slides up. I am currently using a Bootstrap template available at this link. To demonstrate the issue, I created a JSFiddle that can be accessed here. H ...