简体   繁体   English

将一个反应组件放在(z 轴)另一个上

[英]Place one react component over (z-axis) another

I would like to have a band over a component when the component is locked.当组件被锁定时,我想在组件上加一个带子。

The Review component root is a Material UI Paper element that has a host of other elements inside this Paper . Review组件根是一个Material UI Paper元素,在此Paper中有许多其他元素。 There are a half dozen of these particular elements on the page.页面上有六个这样的特定元素。 When locked===true for each element, I want something to sit, centered (vert and horz), on top of the review element.当每个元素locked===true时,我想要一些东西放在评论元素的顶部,居中(垂直和水平)。

I found that a Popover element works fine as it can be moved to center/center.我发现Popover元素可以正常工作,因为它可以移动到中心/中心。 However, being a Modal, it doesn't allow interaction with the rest of the page.但是,作为 Modal,它不允许与页面的 rest 交互。

<Popover
    id={"id"}
    open={Boolean(anchorEl)}
    anchorEl={anchorEl}
    onClose={handleClose}
    anchorOrigin={{
        vertical: 'center',
        horizontal: 'center',
    }}
    transformOrigin={{
        vertical: 'center',
        horizontal: 'center',
    }}
>The content of the Popover.</Popover>

I then ensure that anchorEl points to the correct Paper.然后我确保anchorEl 指向正确的Paper。 This works for a 'popover'... The popper element, which is one that isn't in the modal tree (and thus allows multiple and doesn't steal control of the entire app) doesn't have the positioning needed.这适用于“popover”... popper 元素,它不在模态树中(因此允许多个并且不会窃取对整个应用程序的控制)没有所需的定位。

<Popper id={'popperID'} open={Boolean(anchorEl)} anchorEl={anchorEl} placement={'top'} transition>
  {({ TransitionProps }) => (
    <Fade {...TransitionProps}>
      <div className={classes.busy}>The content of the Popper.</div>
    </Fade>
  )}
</Popper>

This puts the element vertically on top (y-axis) my anchorEl ... which is not what I want.这将元素垂直放置在我的anchorEl顶部(y 轴)......这不是我想要的。

I've also tried just putting another Paper in there, but it just ends up vertically 'below' my component.我也试过把另一Paper放在那里,但它只是垂直地“低于”我的组件。

EDIT: Worth noting I have also tried to position it with CSS.编辑:值得注意的是,我还尝试使用 CSS 对其进行 position。 The problem is that absolute positioning (that should position it relative to the parent) seems to position it relative to the entire app instead of the JSX parent/component.问题是绝对定位(应该 position 它相对于父级)似乎 position 它相对于整个应用程序而不是 JSX 父级/组件。

How can I do this?我怎样才能做到这一点?

Use absolute positioning as you said, but you have to give the parent component/element display: relative .如您所说,使用绝对定位,但您必须给父组件/元素display: relative Absolute positioning works from the closest ancestor that is not statically positioned.绝对定位从最近的非静态定位的祖先开始工作。 https://www.w3schools.com/cssref/pr_class_position.asp https://www.w3schools.com/cssref/pr_class_position.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM