简体   繁体   English

需要在父元素之外创建一个具有溢出自动的元素

[英]Need to make an element outside the parent which have overflow-y auto

In the following code, I need to make the close icon positioned outside the div.在下面的代码中,我需要将关闭图标放置在 div 之外。 I can't use overflow: hidden;我不能使用overflow: hidden; . . Is there anyway to get this sorted without using overflow: hidden;有没有办法在不使用overflow: hidden;情况下进行排序overflow: hidden; or position: fixed for the close div.position: fixed为关闭 div。

JSFiddle of below code here: https://jsfiddle.net/mannyuiux/jhwu9n4r/4/ .以下代码的 JSFiddle: https ://jsfiddle.net/mannyuiux/jhwu9n4r/4/。

<!-- HTML -->
<div tabindex="-1" class="dialog__content dialog__content__active" style="z-index: 202;">
  <div class="dialog dialog--active" style="width: 1000px;">
    <div class="card">
      <div class="close">
        <img src="http://cdn.onlinewebfonts.com/svg/img_211963.png" alt="Close" />
      </div>
    </div>
  </div>
</div>
/* CSS */
.dialog__content {
    align-items: center;
    display: flex;
    height: 100%;
    justify-content: center;
    left: 0;
    pointer-events: none;
    position: fixed;
    top: 0;
    transition: 0.3s ease-in-out;
    width: 100%;
    z-index: 6;
    outline: none;
  }


  .dialog {
    box-shadow: 0px 11px 15px -7px rgba(0, 0, 0, 0.2), 0px 24px 38px 3px rgba(0, 0, 0, 0.14), 0px 9px 46px 8px rgba(0, 0, 0, 0.12);
    border-radius: 2px;
    margin: 24px;
    overflow-y: auto;
    pointer-events: auto;
    transition: 0.3s ease-in-out;
    width: 100%;
    z-index: inherit;
  }
  .dialog:not(.dialog--fullscreen) {
    max-height: 90%;
  }
  .card {
    padding: 0;
    padding-top: 70px;
    background-color: #fff;
    color: rgba(0, 0, 0, 0.87);
    display: block;
    border-radius: 2px;
    min-width: 0;
    position: relative;
    text-decoration: none;
    box-shadow: 0px 2px 1px -1px rgba(0, 0, 0, 0.2), 0px 1px 1px 0px rgba(0, 0, 0, 0.14), 0px 1px 3px 0px rgba(0, 0, 0, 0.12);
  }
  .close {
    position: absolute;
    top: -20px;
    right: 0;
    height: 12px;
    width: 12px;
  }
  .close img {
    max-width: 100%;
  }

The overflow-y: auto; overflow-y: auto; on dialog element is the issue.对话元素是问题所在。 It will behave the same as overflow-hidden in this case, making the child element close icon invisible if it's placed outside.在这种情况下,它的行为与溢出隐藏相同,如果它被放置在外面,则使子元素关闭图标不可见。

If you can't remove the overflow-y: auto;如果你不能删除overflow-y: auto; then you should wrap the dialog in another div (that has no overflow value set but has position: relative set) and then also make the close icon a direct child of that element.那么您应该将对话框包装在另一个 div 中(没有设置溢出值但设置了position: relative ),然后还使关闭图标成为该元素的直接子元素。

Like this:像这样:

<div style="position: relative">
  <div class="dialog dialog--active" style="width: 1000px;">
    <div class="card" />
  </div>
  <div class="close">
    <img src="http://cdn.onlinewebfonts.com/svg/img_211963.png" alt="Close" />
  </div>
</div>

.dialog类中删除overflow-y:auto

暂无
暂无

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

相关问题 如何使使用overflow-y的父级中的div滚动? - How to make scrollable a div in a parent which use overflow-y? html:工具提示在带滚动的拆分屏幕上隐藏为div(需要在父容器上保持“ overflow-y:auto”) - Html: tooltip is hidden behing div on a split screen with scroll (need to keep “overflow-y:auto” on parent container) 在浏览器中测试对overflow-y:auto的支持 - testing support for overflow-y:auto in browsers 如何在不将overflow-x更改为auto的情况下使overflow-y滚动? - How to make overflow-y scroll without changing overflow-x to auto? 设置溢出-y 可见,而溢出-x 是自动的,以便内容可以垂直溢出父容器 - Set overflow-y visible while overflow-x is auto so that content can vertically overflow parent's container 当用户手指超出overflow-y时,如何结束滚动:滚动元素? - How to end scroll when user finger gets outside of overflow-y:scroll element? 位置:带有溢出-y 的 div 内的绝对元素:自动未显示在所需位置 - Position:absolute element inside a div with overflow-y:auto does not show in the desired position 如何使溢流y独立于溢流x运行 - How to make overflow-y operate independently of overflow-x 带有溢出-y的jQuery轮播,以显示容器外部的弹出窗口 - jQuery carousel with overflow-y to show popup outside of container CSS溢出-Y:自动无法在Firefox和Chrome浏览器 - css overflow-y:auto not working in firefox and chrome
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM