Guide to positioning a div at the bottom of a Drawer while maintaining the same width as the Drawer in React Material UI

Creating a Drawer on the right-hand side using <Drawer/>, I am trying to make a <div> stick to the bottom of the <Drawer />. The width of this <div> should match the width of the <Drawer />.

Desired Outcome:

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

To achieve the desired outcome, here is what I attempted:

 const useStyles = makeStyles({
  list: {
    width: 500,
  },
  bottomContainer: {
    position: "fixed",
    bottom: 0,
    display: 'flex',
    flex: 1,
    flexDirection: 'row',
    justifyContent: 'space-between',
    margin: '30px'
 },
});

However, setting position: fixed results in the bottom div looking like this:

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

The entire div becomes merged and does not match the width of the drawer. Alternatively, if I set position: relative, the bottomContainer appears with the same width as the top div and displays below it rather than at the bottom of the <Drawer />.

Setting width: '100%' for bottomContainer causes Abc to appear outside of the <Drawer />.

My question is:

How can I create a <div> with the same width as <Drawer/> and have it appear at the bottom of the <Drawer />?

Answer №1

Utilize the power of flexbox in this particular scenario.

To achieve the desired layout, create a container that defines a specific height and houses both child elements. Apply display: flex, flex-direction: column, and justify-content: space-between.

Within the second div containing two paragraph elements, introduce additional styling with display: flex and justify-content: space-between. Omit specifying flex-direction as it defaults to flex-direction: row. For vertical alignment, include align-items: center.

* {
  margin: 0;
  padding: 0;
}

.flex {
  width: 100%;
  height: 500px;
  background-color: grey;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.div1, .div2 {
  width: 100%;
  height: 100px;
  background-color: red;
}

.div2 {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
<div class="flex">
  <div class="div1"></div>
  <div class="div2">
    <p>abc</p>
    <p>123</p>
  </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

When you type a letter in the middle of a string, the cursor is automatically moved back to the end - Material UI

I designed a ChipInput feature that switches to a string when focused and transforms into a Chip component when blurred, with chips separated by commas. Everything seems to be functioning properly except for one issue I am encountering. Whenever I type in ...

Ways to eliminate dates from the text of listed items

Before finalizing their registration, users on our site are shown a review page. This panel displays all the items they have selected, creating a unique and variable list for each individual. However, each item in the list starts with a distracting date/ti ...

Tips for creating a clickable popover within a window that remains open but can be closed with an outside click

Is there a way to ensure that my popover window remains clickable inside its own area without closing, but automatically closes when clicked outside of the window? This is the code I am currently using, which is triggered by a button click: if (response. ...

Obtaining the element ID with Selenium WebDriver in cases of dynamic IDs

I am encountering an issue with the drop-down image element. I have attempted various methods to select the element, but none of them seem to be working. This may be due to the fact that both elements are identical and their IDs are dynamic. I did manage ...

Discover the process of retrieving an image from the backend with React and Node.js

Hey there! I'm currently working on a Housing blog using ReactJS and NodeJS. One of the tasks I tackled was creating a login controller in NodeJS to send user details, including the image path from the database, to the frontend. The image path is sto ...

"Implementing conditional rendering to hide the Footer component on specific pages in a React application

Is there a way to conceal the footer component on specific pages? app.js <div className="App"> <Header setShowMenu={setShowMenu} /> {showMenu ? <Menu navigateTo={navigateTo} setShowMenu={setShowMenu} /> : null} <Main na ...

Using JavaScript to invoke Applescript commands

Is it feasible to execute Applescript from JavaScript? I would be grateful if someone could offer a sample code or useful reference link. ...

What is the best way to display json data in a react component?

I currently have a JSON file that I am importing into my component with the following code: import { beer, wine, spirits, alcopop } from '../../config/calculator.json'; I’m trying to figure out how to utilize this JSON data within my render m ...

I attempted to install react-compare-image using npm, but encountered an error stating that the dependency tree could not be resolved

PS D:\skinprojecct> npm install --save react-compare-image npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: [email protected] npm ERR! Found: [email protected] npm ERR! node_mod ...

Transforming the data structure occurs when retrieving data from a Flask backend using the React API

I am currently facing a challenge with my flask API backend and react/nextjs frontend. I am attempting to create a basic bar chart using data retrieved from the backend, but I seem to be encountering difficulties in fetching and mapping the data accurately ...

Continuously spinning loading icon appears when submission button is triggered

We are currently experiencing some issues with our mobile forms. Our users utilize a mobile form to submit contact requests, but the problem arises when they hit 'submit' - the loading icon continues to spin even after the form has been successf ...

Executing a drilldown function on initialization of Highcharts/Highmaps

Is there a way to set highcharts and highmaps to start in drilldown mode? Currently, I have a continents map that successfully drills down into countries. But is it feasible to initialize my map in drilldown mode right away...like set it up to already be ...

Trouble authenticating user through express-session with Typescript

I have developed a small app for registration and login, but I am encountering issues with using session-express to maintain the session. Check out server.ts below where I establish session, cors, etc... import express, { json } from "express"; ...

An HTML webpage that automatically refreshes but does't display the iframe content when the underlying HTML page is being updated

I have a script that updates a text file with completed tasks, creating log files in the process. I then use another script to format these logs with HTML code for tables, headings, banners, etc., saving the formatted version as Queue.html. To display this ...

Generating numerous variables simultaneously is a feature of SASS

Is it possible to utilize a SASS map in order to generate individual variables for each key-value pair? For instance, I aim to achieve the following: $heading: ( 1: 5rem, 2: 4.5rem, 3: 4rem, 4: 3.5rem, 5: 3rem, 6: ...

Enhance web design with dynamic size pseudo elements using only CSS, no

Before the title, I've added a pseudo element with a slanted background. When the title is wrapped, it increases in height. I've been attempting to make the pseudo element adjust to the title's height, but haven't succeeded yet. I&apos ...

Showing only the objects that are marked as true in the component (React)

I have implemented two key React components. One of them is VideoGameList.js, it serves as an export of an array containing multiple objects. const VideoGameList = [ { id: 1, title: "Fire Emblem Engage", src: vg01, releaseDate: ...

Using either Javascript or JQuery to update every cell in a particular column of a table

I need to use a button to add "OK" in the Status column of table tblItem, which is initially empty. How can I achieve this using JavaScript or JQuery? The table has an id of tblItem Id Item Price Status 1 A 15 2 B 20 3 C ...

Error: The function "text.toLowerCase()" is not defined

Whenever I execute the following code, I keep encountering this error message: Uncaught TypeError: text.toLowerCase is not a function const getVisibleExpenses = (expenses, { text, sortBy, startDate, endDate }) => { return expenses.fi ...

Customizing colors in Material-UI

I am currently facing an issue with changing the background color of my footer in paper using material-ui with React. I tried following the color sample demo by using createMuiTheme and MuiThemeProvider, but unfortunately, it did not work as expected. I am ...