Can't scroll to top of flex item that is overflowing container

后端 未结 7 2431
再見小時候
再見小時候 2020-11-21 05:08

So, in attempting to make a useful modal using flexbox, I found what seems to be a browser issue and am wondering if there is a known fix or workaround -- or ideas on how to

7条回答
  •  青春惊慌失措
    2020-11-21 05:34

    I managed to pull this off with just 3 containers. The trick is to separate the flexbox container from the container that controls the scrolling. Lastly, put everything into a root container to center it all. Here are the essential styles to create the effect:

    CSS:

    .root {
      display: flex;
      justify-content: center;
      align-items: center;
    }
    
    .scroll-container {
      margin: auto;
      max-height: 100%;
      overflow: auto;
    }
    
    .flex-container {
      display: flex;
      flex-direction: column;
      justify-content: center;
    }
    

    HTML:

    Lorem ipsum dolor sit amet.

    I've created a demo here: https://jsfiddle.net/r5jxtgba/14/

提交回复
热议问题