Is it possible for a scrollable div to fill the space above a BottomNavigation bar?

My current project involves creating a fixed bottom navigation bar, with a scrollable div above it displaying various card lists.

In my attempts to achieve this layout, I consulted both the Material-UI documentation here and here. However, I struggled to place the div above the navigation bar in a way that fills up the remaining space on the screen.

I experimented with fixing the navigation bar to the bottom with a high z-index, but encountered issues where it covered the bottom of the div above. Additionally, using flexbox did not seem compatible with having a fixed navigation bar at the bottom.

My goal is to avoid setting percentage heights for the navigation bar or the div above, as I am concerned about how that might scale across different screen sizes. Any advice on how to approach this challenge would be greatly appreciated.

Answer №1

To avoid using position absolute/fixed due to the lack of a defined height, you can implement a flex container that automatically fills the body with a height: 100vh;. Within this structure, place your content-holder component with styles like flex:1; for maximum expansion and overflow-y: auto; to display a scrollbar if necessary. The actual content goes inside the content-holder.

BottomNavigation should be placed alongside content-holder and will always remain at the bottom.

You can refer to the following example on CodeSandbox, where the relevant code is also provided below:

// JavaScript code snippet
import React from "react";
import BottomNavigation from "@material-ui/core/BottomNavigation";
import BottomNavigationAction from "@material-ui/core/BottomNavigationAction";
import RestoreIcon from "@material-ui/icons/Restore";
import FavoriteIcon from "@material-ui/icons/Favorite";
import LocationOnIcon from "@material-ui/icons/LocationOn";
import "./styles.css";

export default function App() {
  return (
    <div className="app">
      <div className="content-holder">
        <div className="content">
          <h1>Hello CodeSandbox</h1>
          <h2>Start editing to see some magic happen!</h2>
        </div>
      </div>
      <BottomNavigation>
        <BottomNavigationAction label="Recents" icon={<RestoreIcon />} />
        <BottomNavigationAction label="Favorites" icon={<FavoriteIcon />} />
        <BottomNavigationAction label="Nearby" icon={<LocationOnIcon />} />
      </BottomNavigation>
    </div>
  );
}
/* CSS styling */
body {
  margin: 0;
  padding: 0;
}

.app {
  font-family: sans-serif;
  text-align: center;
  background-color: lightgreen;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.content-holder {
  flex: 1;
  overflow-y: auto;
}

.content {
  /* This style is optional since it grows based on the content */
  min-height: 200vh;
}

Answer №2

Perhaps the solution came too late, but incorporating padding at the bottom of your content container could prove useful.

padding-bottom:60px;

This method worked effectively for me in relation to the bottom navigator on material-ui!

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

Mastering the art of utilizing particles.js

Particles.js doesn't seem to be functioning properly for me—I'm struggling to pinpoint the issue. Any guidance or suggestions would be greatly welcomed, as I'm unsure whether it's related to an external dependency... HTML: <div ...

Guide on achieving 'justify-content: center' with MUI Pagination?

I have been attempting to center the contents within the Pagination component, but so far, my efforts have been unsuccessful. After inspecting the console, I noticed that styling the ul wrapper needs justification, yet there doesn't seem to be any rel ...

Is there a way to incorporate a delete button for each li element that is included in my list?

I have successfully implemented a to-do list where clicking on an item strikes a line through it and there is a delete button that works. However, I am looking for assistance on how to create a delete button for each newly added li item. var button = do ...

When the submit button is clicked on a React form, it not only submits the current form

I am working on a React application with multiple forms, where each form is rendered based on the current page index. I would like the "Next" button that retrieves the next component to also act as a submit button. The issue I am facing is that while the n ...

Creating rows within a table in React.js using the map method: Techniques to follow

Here is my code snippet: const [tasks, setTasks] = useState(''); I am simulating data with a mock server. function fetchTasks() { axios.get('http://localhost:4000/tasks') .then(function (response) { ...

What is the best way to pass a reference from one component to another component using a mapped list?

Here is an array of objects representing services: export const serviceList = [ { title: "Exterior Services", image: "/images/service-card-images/kendall-painting.webp", description: "ExteriorServicesDescription" ...

Adjusting the header background color as the user scrolls on a Next.js webpage

When looking at the code below: import { useEffect } from "react"; import Link from "next/link"; import styles from "./header.module.css"; import { useRouter } from "next/router"; export default function Header() { ...

Struggling to insert a high-quality image into inline divs of exactly 33.3333% width

After creating 3 inline divs, each taking up 33.333% of their parent width, I encountered an issue while trying to insert images into them. Whenever the image exceeds the 33.333% width of the div, it overflows outside the container. My goal is to make the ...

Highlighted top and bottom borders accenting a vertical list

I am working on a list that contains four items. Each item should have top and bottom borders set to 1px solid grey by default. There is a JavaScript rotator in place that adds a 'highlighted' class to the selected list element, which should have ...

Formik initialization does not prevent undefined errors in MUI textfield error and helpertext

It's perplexing why I keep encountering this issue - it has popped up a few times when attempting to utilize nested objects with Formik, React, and TypeScript. It appears that Formik is not compatible with data containing nested objects? https://i.st ...

Creating a tooltip for new list items: A step-by-step guide

I'm currently working on creating a tooltip using JQuery for incoming list items. Users will input text in a textfield, press enter, and those values will be displayed in a visible list on the website. I intend to have a tooltip associated with each i ...

Enhance npm package by implementing custom functionality with React Component

I have designed an app that bears a striking resemblance to the following code: class MyCustomApp extends React.Component { constructor (props) { super(props) this.state = { tags: [ { id: 1, name: "Oranges" }, { id: 2, ...

Guide on Applying a Dynamic Color in VueJs 3 Composition API/Vuetify Using CSS

Currently, my project utilizes Vue 3 with the composition API and Vuetify for the UI. I am looking to utilize a color that is already defined in a Vuetify theme variable within my CSS, similar to how I have done it previously in JavaScript. Although I at ...

Material-UI version 5 Datepicker now has the ability to expand seamlessly to fit the entire width of its parent

When using Material-UI v4, the Datepicker component could accept the fullWidth prop. But in version 5 of Material-UI, this prop is not mentioned in the component API. Since all css selectors for this component are non-deterministic, I am having trouble a ...

Refreshing a React page will lead to props being empty

The situation I am facing is that the code appears to be correct, but for some reason, when the web page loads, this.props.items does not seem to be passed to Item. Strangely, when I attempt to display this.props.items in console.log, nothing shows up. How ...

Error: The parent class is not defined as an object

My program is currently attempting to utilize this.state, but I encountered an error. Can anyone provide assistance on resolving this issue? https://i.stack.imgur.com/wgxBf.png ...

Adjusting text to begin after a variable by two spaces (equivalent to 5 pixels)

When displaying the echoed text below, I noticed that "DURING" sometimes overlaps with the variable $submittor when there are not enough &nbsp;s. On the other hand, if too many &nbsp;s are added, there ends up being excessive space between $submitt ...

Tips on positioning a div based on the screen dimensions

In my table, there is an icon that reveals a chart as a popup when hovered over. This div is where the chart is displayed: <div id="chart-outer" style="@style" class="popup-chart close"> <h2 id="charttitle&q ...

distinguish different designs for individual components in Angular 5

My project is divided into two main parts: one for public web pages and the other for an admin control panel. Each part has its own set of CSS and javascript files for custom templates. If I include all CSS and js files in index.html, they all load at the ...

React: Using Chart.js to visualize negative values with a different color in the area

I am implementing a line chart using Chart.js and react-chartjs-2 to display positive and negative values. For positive values, I want the filled area to be green, and for negative values, I want it to be red. Check out the code here import React from &qu ...