Element positioning in Material UI is fluid and responsive across all devices, with the ability to place elements at

As a novice in layout design, I am currently developing a web application for both mobile and desktop using React and Material UI. My challenge lies in placing the app navigation at the bottom of the screen. The issue arises because the location of the app navigation differs on various mobile devices such as iPhone X and iPhone 7. How can I make sure that it is responsive across multiple mobile devices, and potentially on tablets and desktops as well?

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

https://i.sstatic.net/kftkI.png
Here is my React and Material UI code:

const useStyles = makeStyles({
  divContainer: {
    display: 'flex',
    alignItems: 'flex-end',
    height: '99vh',
  },
  root: {},
});

export default function SimpleBottomNavigation() {
  const classes = useStyles();
  const [value, setValue] = React.useState(0);

  return (
    <Container className={classes.divContainer}>
      <BottomNavigation
        value={value}
        onChange={(event, newValue) => {
          setValue(newValue);
        }}
        showLabels
        className={classes.root}
      >
        <BottomNavigationAction label="Home" icon={<HomeRoundedIcon />} />
        <BottomNavigationAction label="Wishlist" icon={<FavoriteIcon />} />
        <BottomNavigationAction
          label="Add"
          icon={<AddCircleOutlineRoundedIcon />}
        />
        <BottomNavigationAction
          label="Notifications"
          icon={<NotificationsIcon />}
        />
        <BottomNavigationAction
          label="Profile"
          icon={<AccountCircleRoundedIcon />}
        />
      </BottomNavigation>
    </Container>
  );
}

Answer №1

sandbox

Implement the root in the useStyle like this:

const useStyles = makeStyles({
  root: {
    position: "fixed",
    bottom: "0px",
    left: "0px",
    right: "0px",
    marginBottom: "0px",
    width: "100vw",
    backgroundColor: "red",
}
});

Next, assign it as the className for the BottomNavigation component:

<BottomNavigation
      value={value}
      onChange={(event, newValue) => {
        setValue(newValue);
      }}
      showLabels
      className={classes.root}
    >

This will ensure that the component is located at the bottom of different devices.

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

How come the nth-child selector remains unaffected by other selectors?

Here is an example that I have created for this issue: http://jsfiddle.net/SXEty/ <style> table td, th { padding: 8px; text-align: left; } table td:nth-child(1) { color: red; } table td { color: blue } </style> ... <table> <tr> ...

Transferring state data using the useState hook between two functional components

I have a project with two function components that use useState in separate files. My goal is to display the URL on my FaceRecognition component when fetchSuccess is set to true. const ImageLinkForm = () => { const [url, setUrl] = useState(""); co ...

Unique phrase: "Personalized text emphasized by a patterned backdrop

I'm facing a challenge and struggling to find a way to highlight text using CSS or jQuery. My goal is to have an image on the left, another one on the right, and a repeated image in between. Since there are some long words involved, I need a dynamic s ...

`CSS border issues`

I am currently attempting to create a square consisting of 4 smaller squares inside, but I have been facing challenges with the method I was using. Here is the code snippet: #grandbox { position: absolute; width: 204px; height: 204px; border: so ...

JavaScript code to toggle the navigation bar on mobile devices

I am experiencing an issue with a script that is not performing the desired task. I am looking for a script that can add the Class "active" to a ul element with the id "btnMob0". Currently, my script looks like this: <script type="text/javascript"> ...

Is it necessary for me to use a .jsx extension when saving my React component files?

After working with React for a few months, I recently noticed that some of my files have the .js extension while others have the .jsx extension. Surprisingly, when I write JSX code in the .js files, everything still functions correctly. Is there any signif ...

Material UI: Issue with implementing the dark theme

I've implemented the Context API to store the theme value. The theme itself is generated using <createMuiTheme> and passed down from <Layout> to its children through <MuiThemeProvider> and <CssBaseline>. Although I can observe ...

Adding custom styles to an unidentified child element in React using Material-UI

When the function below is executed in a loop, I need to include styles for the icon which will be passed as an argument to the function. The icon element will be an unspecified React Material-UI Icon component. const renderStyledCard = (lightMode, headi ...

What is the best way to efficiently manage NPM dependencies in projects when faced with conflicting versions?

My goal is to create the playground app for react-native-navigation following the instructions provided here. However, a simple npm install does not work due to the peer dependencies specifying react: "*" and react-native: "*". As of to ...

Every fourth list item, beginning with a designated number

I'm attempting to add a border to specific list items in my HTML. I want the border to start from the 9th child and then continue every 4th child after that. For clarification, I'd like the 9th, 13th, 17th, 21st, 25th... list items to have white ...

Display the execution duration on an HTML document

Recently, I created a loan calculator using Javascript and now I'm contemplating on incorporating the time taken for the code to execute into the results. My intention is to have the execution time displayed on my HTML page, but I am unsure of how to ...

The issue with the react-diagram stemmed from a conflict with @emotion/core

During the installation of react-diagrams by projectStorm, I encountered some errors which are shown in the following image: errorImg Despite attempting to downgrade the version of '@emotion/core' to ^10.0.0, the issue persisted. Here is a view ...

Keep track of the toggled state and prevent any flickering when the page is reloaded, all without the

After extensive searching, I couldn't find exactly what I needed. Therefore, I decided to utilize cookies to remember the toggled state of a div whether it's hidden or visible. However, I encountered an issue where there is flicker happening as t ...

Incorporating Node modules within a Spring Boot executable JAR

I am currently working on a Spring Boot application with a React front end. In my project, I have node dependencies managed by package.json and Spring Boot dependencies handled by Gradle. As I prepare to build a jar for my production environment, I am unc ...

Legend alignment issue in Firefox disrupting Flexbox functionality

My fieldset has a legend containing text and a button. I am attempting to use flexbox to right-align the button within the legend. This setup works correctly in Chrome, but encounters issues in Firefox. I have managed to replicate the problem with a simpl ...

Guide on customizing the react-notification-system demo for a fluxible project

I've been experimenting with incorporating the react-notification-system component into a standard fluxible project. I'm seeking advice on how to modify the sample code to fit an ES6 style class. Here is the original sample code: import React f ...

CSS effect() Practical duration

I have successfully implemented a CSS filter to blur an element, however, I am looking for a way to make the blur ease in smoothly. I'm not sure which css property controls this easing effect? Initially, I tried using transition: 1s; but that ended u ...

Guide on removing material-ui from your project and updating to the newest version of MUI

I need to update my React app's material-ui package to the latest version. Can someone provide instructions on how to uninstall the old version and install the new MUI? UPDATED: In my package.json file, the current dependencies are listed as: ...

The numbers on MaterialDatePicker calendar are not centered correctly

Description: The numbers are not centered Expected outcome: Ensure the numbers are aligned in the center Source code: Please note that this issue was present even before any styles were added <style name="OeamtcThemeOverlay_MaterialCalendar" par ...

React JS - Large image failing to display entirely

I'm currently facing challenges with displaying my image in full size. I am unsure what is causing this issue and would appreciate any guidance on correcting my approach. The specific image I am attempting to display at full-size can be found Howeve ...