Search code examples
htmlcssscrolloverflowhidden

Is there a way of hiding a scroll bar when using overflow-y:auto?


Aiming to hide the scroll bar I used

      &:hover{
      max-height: calc(100vh - 100px);
      overflow:auto;
      }

However, my main problem is that the width of the element containing the sidebar changes to give space to the scrolling section. Is there a way of avoiding this or hiding the scrolling completely and still be able to scroll?

Here's my CodePen if you find it easier: https://codepen.io/fergos2/pen/MWgLqgL?editors=1100

(find the code below without the lipsum)

Thanks in advance for helping this newbie!

.container {
  width: 100%;
  margin: 0 auto;
  background-color: #eee;

  display: grid;
  grid-template-rows: min-content 1fr;
  grid-template-columns: 1fr 2fr 1fr;
  grid-gap: 15px;

  grid-template-areas: "head head head"
                       "leftbar main rightbar";

  & > * {
    background-color: pink;
    color: #ggg;
    font-size: 20px;
    font-family: sans-serif;
  }
}

  .pd {
    padding: 15px;
  }

  .header {
    grid-area: head;

    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 10;

    box-shadow: 0 15px #eee;
  }

  .left-sidebar {
    grid-area: leftbar;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;


    .left-inner {
      position: -webkit-sticky;
      position: sticky;
      top: 70px;

      &:hover{
      max-height: calc(100vh - 100px);
      overflow:auto;
      }


      // overflow-y: auto;
    }

    .box-1 {
      color: red;
      border: 1px solid purple;
      margin-bottom: 5px;
    }

    .footer {
      color: green;
      border: 1px solid purple;
    }
  }

  .main-content {
    grid-area: main;
  }

  .right-sidebar {
    grid-area: rightbar;

     display: flex;
     flex-direction: column;
     justify-content: flex-start;

      .box-2 {
        color: red;
        border: 1px solid purple;
        margin-bottom: 5px;
      }

      .box-3 {
        color: green;
        border: 1px solid purple;
      }

    .right-inner {
      position: -webkit-sticky;
      position: sticky;
      top: 70px;
    }
  }
<div class="container">
  <header class="header pd">Header</header>



    <div class="left-sidebar pd">
      <div class="left-inner">
        <div class="box-1 pd">
        Box-1
      </div>
      <footer class="footer pd">
        Footer
      </footer>
      </div>
    </div>

    <div class="main-content pd">
      Main content 
    </div>


    <div class="right-sidebar pd">
      <div class="right-inner">
              <div class="box-2 pd">
        Box-2
      </div>
      <div class="box-3 pd">
        Box-3
      </div>
      </div>
    </div>


</div>

UPDATE

It worked by using the code shown in my answer below.


Solution

  • The following worked for me

    ::-webkit-scrollbar
    {
      width: 0px;  /* for vertical scrollbars */
      height: 0px; /* for horizontal scrollbars */
    }
    
    ::-moz-scrollbar {
      width: 0px;
      height: 0px;
    }