Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to overlay a component on top of another

I want to implement a floating action button and I want to overlay it on other pieces of a component but in anyways it goes under the other components, even when I try to implement it in the parent component.

I want to implement it from material UI Floating action button

Here is what I've tried before:

const fabstyle = {
        margin: 0,
        top: 'auto',
        right: 20,
        bottom: 20,
        color:'green',
        left: 'auto',
        position: 'fixed',
};
return (
    <div >
        <Fab style={fabstyle}></Fab>
    </div>
)
like image 487
louis Schneider Avatar asked Jan 27 '26 00:01

louis Schneider


1 Answers

there are multiple ways to achieve this one is with grid, the other which is simpler is making your parent component relative (position: relative) and the children component absolute (position: absolute).

Then you can position the children element with the values: *top, left, bottom and right

.parent {
    position: relative;
}

.children {
   position: absolute;
   top: 0;
   left: 0;
}

In the example above, the children will be rendered in the top left corner of the parent component

like image 61
GBra 4.669 Avatar answered Jan 28 '26 13:01

GBra 4.669



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!