Alignment and spacing in a flexible direction

Hello, I am developing a bar app.

 <AppBar position="sticky" className={classes.appBar} >
        <Container maxWidth="lg">
        <Toolbar className={classes.root}>
        <Typography noWrap>
        <img src={require("./nodejs-icon.svg")} alt="bug" height={100} />
          </Typography>
              <SearchIcon color="secondary" />
            <InputBase
              placeholder="Search…"
              classes={{
                root: classes.inputRoot,
                input: classes.inputInput,
              }}
              inputProps={{ 'aria-label': 'search' }}
            />
          {auth && (
            <div>
              <IconButton
                aria-label="account of current user"
                aria-controls="menu-appbar"
                aria-haspopup="true"
                onClick={handleMenu}
                color="secondary"
              >
                <ShoppingCartOutlinedIcon  style={{ fontSize: 50 }} />
              </IconButton>
              <Menu
                id="menu-appbar"
                anchorEl={anchorEl}
                anchorOrigin={{
                  vertical: 'top',
                  horizontal: 'right',
                }}
                keepMounted
                transformOrigin={{
                  vertical: 'top',
                  horizontal: 'right',
                }}
                open={open}
                onClose={handleClose}
              >
                <MenuItem onClick={handleClose}>Profile</MenuItem>
                <MenuItem onClick={handleClose}>My account</MenuItem>
              </Menu>
            </div>
          )}
        </Toolbar>
        </Container>
      </AppBar>

Furthermore, I have the following CSS settings:

const headerStyle = (muiBaseTheme => ({
  root:{
    padding: 0,
    margin: 0,
    display: 'flex',
    width: '100%',
    background: "#fff",
    }, 
    appBar:{
      background: "#fff",
      boxShadow:
      "0 2px 2px 0 rgba(0, 0, 0, 0.0), 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 1px 5px 0 rgba(0, 0, 0, 0.0)",
    },
    flexEnd:{
      alignItems: 'flex-end'
    },
    flexStart:{
      alignItems: 'flex-start'
    },
    flexCenter:{
      alignItems: 'center'
    }
}))

I defined my toolbar with flex display and would like to align items and create spacing.

I want the image at the beginning.

The input should be in the center.

And the icon at the end.

However, I am unsure how to achieve this responsively.

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

Answer №1

To align the elements within your Toolbar, simply add the CSS property justify-content: space-between; to the parent element. This will create the desired spacing between the child elements. For more information, you can refer to this resource. I have provided a sample code snippet that demonstrates this concept below:

.appbar,
.container,
.toolbar{
  width: 100%;
}

.toolbar{
  display: flex;
  /* Apply justify-content property here */
  justify-content: space-between;
}

.toolbar > div{
  display: inline-block;
  width: 30px;
  text-align:center;
}

.toolbar > div:nth-child(1){
  background:red;
}
.toolbar > div:nth-child(2){
  background:yellow;
}
.toolbar > div:nth-child(3){
  background:green;
}
<div class="appbar">
  <div class="container">
    <div class="toolbar">
      <div>a</div>
      <div>b</div>
      <div>c</div>
    </div>
  </div>
</div>

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

Enhancing State in React and Redux Saga with the Addition of New Objects

I have data structured like this. export const initialSettings = { id: '01', name: '', lat: '', long: '', adressLine1: '', adressLine2: '', city: '', state: '&apo ...

Footer content spilling out of the wrapper div

My web page has a footer content that is overlapping the wrapper div due to some issues with my css and html. Even when I tried changing the height to auto, it didn't resolve the problem. Below is an example of the current state of the page I am worki ...

Incorporate descriptive text to my HTML slider

How do I customize my carousel to display unique titles or captions for each slide? Here is the code snippet provided: <h1>Incredibly Basic Slider</h1> <div id="slider"> <a href="#" class="control_next">>></a> < ...

Styling elements with CSS can sometimes lead to unexpected behavior in Safari on iOS devices, especially

Ever since the release of iOS 14, I've noticed that content within a div element with an 'overflow-y: scroll' property no longer functions properly on Safari. Does anyone happen to have a solution for this? (Or maybe my code just needs some ...

Styling images and text in CSS within a jQuery UI autocomplete widget

I am currently using an autocomplete widget that displays text along with images. The results I have right now are not meeting my requirements. I want to customize the appearance of my results so that the words 'test' and either 'Federico&a ...

The height of the ReactPlayer dynamically adjusts to accommodate content beyond the boundaries of the page

I have a video on my webpage that I want to take up the entire screen, but currently, users have to scroll a bit to reach the bottom, which is not ideal. This is my JavaScript: <div id="page"> <div id="video-container"> ...

Include a new item into an array of objects using React Recoil

How can I add a new item to an array of objects in React Recoil when the ID does not match? const [cart, setCart] = useRecoilState(cartItems) New Object: {id:1, quantity:1, productName:'apple'} const addToCart =(newObject) => { ...

Error: The default export is not a component compatible with React in the specified page: "/"

I'm facing an issue while building my next app. Despite using export default, I keep encountering an error that others have mentioned as well. My aim is to create a wrapper for my pages in order to incorporate elements like navigation and footer. vi ...

leveraging a callback function alongside the useState hook

I'm facing an issue with the change() function. My goal is to call the filteredData() function after the setState operation is completed. Typically, I would use a callback function for this task, but useState doesn't support callbacks. Using useE ...

Tips for changing the state of a parent DOM element from a child component several levels deep in a React application

I am currently incorporating both react-router-dom and Material-UI into my application. Below is a basic example I have created using the following files: routes.tsx import { Outlet, createBrowserRouter } from "react-router-dom" const App = () ...

Tips for increasing a variable by one with each button click?

I have a simple JavaScript function called plusOne() that is designed to increment a variable by 1 each time a button is clicked, and then display the updated value on a webpage. However, I'm encountering an issue where the addition only occurs once. ...

spark of unique substance

Having trouble with cycle2 as all images are briefly displayed when the page loads. I tried the recommended solution http://jquery.malsup.com/cycle/faq.html but it didn't stop the flashing, indicating a different issue: The suggested fix for Cycle is ...

Issue with static resource fetching when referencing a .js file within an HTML document while using Flask

My HTML file loads my OpenLayers JavaScript file (which displays a map frame) when opened directly. However, when running the HTML from my Flask python app, the JavaScript file/object fails to load (resulting in no map display, just some heading text). I ...

A guide on invoking an onclick function within a Template literal in React.js

I am seeking assistance with implementing an on-click function using template literals in React JS. When a button within the template literal is clicked, I want to trigger another function in React JS. addPopupToLayer = (surface, layer) => { cons ...

Applying CSS to Dynamic JavaScript Elements: A Guide to Styling Without In-line Code

I'm a beginner in web development and I've been experimenting with applying styles to dynamically generated div elements using JavaScript. So far, I've only been able to manually add inline styling through this function: function applyStyle( ...

use angularjs directive to position a div absolutely aligned with the right edge of another div

I am attempting to use an angularjs directive to align the right side of an absolute div with another div. The code is working, but I am encountering an issue where the children divs are slightly wider than their parent, causing the offsetWidth value to be ...

Issues concerning the application of Nextjs and tailwind styling have arisen

My goal is to achieve a scroll effect where my navbar changes color as the user scrolls down the page. However, I am currently facing an issue where the colors are not registering inside the ('') and the navbar remains white (#ffffff) regardless ...

Setting a default value in a multi-select dropdown using react-select

I have taken over management of my first React app, and I am facing a seemingly simple change that needs to be made. The modification involves an email signup page where users can select their interests from a multi-select dropdown menu. My task is to mak ...

Adding a border to my image that extends to the edges of the page

.overlay{ position:absolute; top:0; left:0; height:100%; width:100%; background:url(hex-shape.png) no-repeat center; z-index:99999; } I have created an overlay background image that covers the entire page. I want the area surrounding the ove ...

What is the best way to enlarge an image while keeping it contained within a card using Bootstrap?

Is it possible to create a visually appealing card similar to the image provided using Bootstrap 5.3.3 and HTML on a website? https://i.sstatic.net/OH4U0.png ...