Position the Material UI Box element to the bottom of its parent container

Hello there, I've come across the following layout:

  <Box width="100%" height="100%" p={1}>
       <Box my={1} display="flex" justifyContent="center">
                                  
       </Box>
       <Box color="text.disabled">
                               
       </Box>
       <Box mt={3}>
         position at bottom
       </Box>
 </Box>

My goal is to properly align the box at the bottom of its parent element. I have attempted the following solutions:

marginTop: "auto" bottom: 0

Unfortunately, none of these approaches seem to be successful in achieving the desired outcome.

Answer №1

If you want to create a positioned box, try using the position="absolute" attribute. Check out these helpful examples: It's crucial that the parent box is also given a positioning. Here is an extended version of your code:

<Box width="100%" height="100%" p={1} position="relative">
   <Box my={1} display="flex" justifyContent="center">
                              
   </Box>
   <Box color="text.disabled">
                           
   </Box>
   <Box mt={3} position="absolute" bottom="0px">
     position at bottom
   </Box>
</Box>

Answer №2

If you want to achieve a layout like this, you can utilize flexbox in your CSS.

#wrapper {
  display: flex;
  flex-direction: column;
  height: 500px;
}

#header {
  background-color: salmon;
  min-height: 100px;
}

#content {
  background-color: lightgreen;
  min-height: 100px;
  flex-grow: 1;
}

#footer {
  background-color: lightblue;
  min-height: 50px;
}
<div id='wrapper'>
  <div id='header'></div>
  <div id='content'></div>
  <div id='footer'></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

[CSS] What's the trick to getting it to smoothly glide to the top?

As a new designer, I have a question about how to make the background color extend to the top without any white space. Can someone please guide me on how to achieve this? <!DOCTYPE html> <html> <head> <style> body{ margin: 0px; p ...

Dynamic row addition in Material Design Lite table causes format to break

Here's the HTML markup for creating a checkbox using material-design-lite: <label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="checkbox"> <input type="checkbox" id="checkbox" class="mdl-checkbox__input" /> <span c ...

Tips for preventing a column from extending beyond the edge of the browser window during resizing

Issue arises when I resize the browser window, causing the left box to extend beyond the browser boundary, making it impossible to see the contents even with the scrollbar below. <!DOCTYPE html> <html lang="en"> <head> ...

CSS: Unexpected value, received NaNrgb

I was attempting to incorporate a checkbox into a Bootstrap form that turns green when it is checked. Here is the code I used: function updateColor() { $("#check1").animate({ "background-color": "rgb(209, 231, 221)" }); } <script src="http ...

React Material-UI: Trouble with Checkbox Toggle

I'm encountering an issue with my React code where the checkbox is not toggling when clicked. Here is the link to the codesandbox: https://codesandbox.io/s/inspiring-kirch-q6p4h The checkbox state initialization looks like this: const [checkbox, set ...

spaces between sections with no padding or borders

I came across the following layout on the web and noticed that the divs do not align perfectly. The top of a lower div does not touch the bottom of the div above it when borders are removed, although they do when borders are added. There seems to be an i ...

What is the best way to initialize React-map-gl with the user's current location as the default latitude and longitude?

Is there a way to render the map with default values of viewport set to user's location without needing to click a locate me button? <ReactMapGL mapboxApiAccessToken={mapboxApiKey} mapStyle="mapbox://styles/mapbox/streets-v11" ...

Issue with displaying InputLabel in Material-UI FormControl

https://i.stack.imgur.com/pJznX.jpg The image shows that my label is positioned behind the outline, and I'm uncertain as to why. I did not apply any specific style other than setting a minWidth property, yet it appears broken with the label hiding be ...

Unable to adjust the padding of a div while the Bootstrap 4 navbar is in a collapsed state on mobile devices

I am facing an issue with a fixed navbar at the top of my page. Below the navbar, I have the page content which includes a Bootstrap 4 image carousel. The problem arises on mobile devices where I need to add top-padding to the page-container (below the nav ...

How to Insert JSON into React Component's Attribute?

I am struggling with setting the value of a React component using JSON in the attribute. I want to concatenate a letter or word, but it doesn't seem to work. Is there a correct way to combine strings within a Component's attribute? In this case, ...

Trouble sliding with Material UI Slider

I've encountered an issue with my Material UI slider - it doesn't slide when clicked and dragged. I followed one of the examples on the Material UI website (https://material-ui.com/components/slider/) and included an onChange function. The values ...

"Using MaterialUI: Opting for a Snackbar Instead of a

Working with React and implementing the Material UI library, I have constructed the following component structure: <RootContainer> <SnackBar /> <HomeContainer> <LoginModal /> </HomeContainer> </RootContainer> ...

What is the best way to locate two specific fields from two distinct models within mongoDB?

The initial model is known as --> Post The subsequent model is referred to as --> User locate ({fieldA = true in Post} and locate ({fieldB = true in User}) then distribute the outcome as a JSON document. ...

Version 13 of NextJS seems to be experiencing issues with the onClick event, but fear not as the component is utilizing the 'useClient

I was attempting to incorporate the select component into my project when I encountered an issue with the onClick function. It seems that it was not working properly, even though I made use of 'use client;' for my component. "use client" ...

Aligning the <div> list to the center of the webpage

Is there a way to center this list element on the page? It consists of three boxes that are all the same size, and I want them to always remain in the middle. body { width: 100%; } .boxes { display: block; margin: 0 auto; } .box-container ...

Positioning divs around a circle can be quite challenging

Among my collection of divs with various classes and multiple child divs representing guests at a table, each main div symbolizes a specific restaurant table type. I have created a jsfiddle for demonstration. http://jsfiddle.net/rkqBD/ In the provided ex ...

Is there a method, like using jQuery, to insert `<br>` tags into each line of a dropdown select list?

I need help with implementing a select tool in a limited horizontal space with each line containing a lot of information. I attempted to embed a tag into the line but it didn't work. Are there any solutions available that could provide a simple fix ...

Exploring the ins and outs of utilizing pseudo selectors with material-ui

I've been attempting to accomplish a simple task. I wanted to toggle the visibility of my <TreeMenu/> component in material UI v1 using pseudo selectors, but for some reason it's not working. Here is the code: CSS: root: { ba ...

Changing animation during mouse hover off

I've been experimenting with using 'translate3d' and 'transition' on hover to animate a div into view. While the animation works smoothly when hovering over the element, I'm having trouble getting it to transition back out of ...

Discovering the compiled CSS file in React when using Sass: A step-by-step guide

In my React project, I have incorporated SASS. Now I am looking to find the final compiled CSS file from that SASS code. Whenever I navigate to: While there is the SCSS file visible, where can I locate the CSS version? I am referring to the compiled outp ...