CSS overflow-x: visible; and overflow-y: hidden; causing scrollbar issue

后端 未结 6 868
孤街浪徒
孤街浪徒 2020-11-21 06:27

Suppose you have some style and the markup:

6条回答
  •  终归单人心
    2020-11-21 07:12

    I've run into this issue when trying to build a fixed positioned sidebar with both vertically scrollable content and nested absolute positioned children to be displayed outside sidebar boundaries.

    My approach consisted of separately apply:

    • an overflow: visible property to the sidebar element
    • an overflow-y: auto property to sidebar inner wrapper

    Please check the example below or an online codepen.

    html {
      min-height: 100%;
    }
    body {
      min-height: 100%;
      background: linear-gradient(to bottom, white, DarkGray 80%);
      margin: 0;
      padding: 0;
    }
    
    .sidebar {
      position: fixed;
      top: 0;
      right: 0;
      height: 100%;
      width: 200px;
      overflow: visible;  /* Just apply overflow-x */
      background-color: DarkOrange;
    }
    
    .sidebarWrapper {
      padding: 10px;
      overflow-y: auto;   /* Just apply overflow-y */
      height: 100%;
      width: 100%;
    }
    
    .element {
      position: absolute;
      top: 0;
      right: 100%;
      background-color: CornflowerBlue;
      padding: 10px;
      width: 200px;
    }

    Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?

提交回复
热议问题