简体   繁体   English

我可以将父容器设置为溢出:隐藏但只有特定的子元素表现得好像父容器是溢出的:可见吗?

[英]Can I set the parent container as overflow: hidden but only specific child elements behave as if the parent is overflow: visible?

I have two child elements that are select field dropdowns inside of a parent container.我有两个子元素,它们是父容器内的 select 字段下拉列表。 The parent container is a modal I made for my project.父容器是我为我的项目制作的模态。 I also have other children elements such as a title, text, and a button.我还有其他子元素,例如标题、文本和按钮。 I only want my two select field dropdowns to behave as if the parent container's overflow is set to visible but the children elements behave as if the parent container's overflow is set to hidden.我只希望我的两个 select 字段下拉列表的行为就像父容器的溢出设置为可见一样,但子元素的行为就像父容器的溢出设置为隐藏一样。

Essentially I want my drop downs to be visible outside of the parent when a user clicks the select field and the dropdown drops.本质上,当用户单击 select 字段并且下拉菜单下降时,我希望我的下拉菜单在父项之外可见。 While the other children are clipped within the parent container when I minimize the modal.当我最小化模式时,其他孩子被剪裁在父容器内。 I had 'modal-container' initially set to overflow: visible so my dropdowns were visible outside of the parent but when I minimized my modal, the rest of the children elements were visible outside of my parent container.我将“模态容器”最初设置为溢出:可见,因此我的下拉菜单在父容器外部可见,但是当我最小化模态时,子元素的 rest 在父容器外部可见。

Here's a general layout:这是一个总体布局:

 <div className="modal-container">
      <div className="modal-inner-container">
        <h4 className="modal-header">header</h4>
        <div className="modal-text">
           <p>some text</p>
        </div>
        <div className="modal-dropdown-container">
           <div className="modal-dropdown></div>
           <div className="modal-dropdown></div>
        </div>
        <button className="modal-button">
      </div>
</div>

Is there any way to pull this off?有什么办法可以解决这个问题吗? I would need my dropdowns to be in between my text div and button so position absolute doesn't apply in this case if I want my dropdowns relative to them.我需要我的下拉菜单位于我的文本 div 和按钮之间,所以如果我想要我的下拉菜单相对于它们,那么 position 绝对不适用于这种情况。

I'm open to other suggestions.我愿意接受其他建议。

Possibly you can do this with position: absolute;可能你可以用position: absolute; 'on the children you want to overflow. '你要溢出来的孩子。 Take a look at this example I made.看看我做的这个例子。

 .contain { height: 100px; width: 100px; background-color: red; overflow: hidden; }.child1 { height: 30px; width: 30px; background-color: blue; }.child2 { height: 200px; width: 200px; background-color: yellow; position: absolute; }
 <div class="contain"> <div class ="child1">one</div> <div class ="child2">two</div> </div>

As you can see, child 2 expands beyond its parent even though the parent has an overflow that's hidden.如您所见,即使父项有一个隐藏的溢出,子项 2 也会扩展到其父项之外。

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

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