最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to overlay a component on top of another - Stack Overflow

programmeradmin3浏览0评论

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

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>
)

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

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>
)
Share Improve this question edited Jan 10, 2021 at 13:16 Pentium1080Ti 1,0561 gold badge8 silver badges16 bronze badges asked Jan 9, 2021 at 21:18 louis Schneiderlouis Schneider 1212 gold badges2 silver badges10 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 7

there are multiple ways to achieve this one is with grid, the other which is simpler is making your parent ponent relative (position: relative) and the children ponent 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 ponent

Make your parent ponent Position Relative & child ponent Position Absolute. It will enable you to position your child element the way you want.

#Parent {
position: relative;
}

#Child {
position: absolute;
//Set the top,left,bottom & right properties the way you want to style your ponent
}

You can use the z-index property in the CSS class

Usage:

.myBoxOnTop {
    z-index: 3;
}

.myBoxOnBottom {
    z-index: 2;
}

发布评论

评论列表(0)

  1. 暂无评论