html – Vertical overflow always showing scrollbar which never works-ThrowExceptions

Exception or error:

I have a sidebar with a menu with icons. When it overflows vertically you should be able to scroll the menu vertically so I am using overflow-y: scroll and the parent has overflow-y auto. However, scrolling is not working at all.

  • the scroll bar is always showing, even when the content isn’t overflowing (just try removing half of the list items in my fiddle and you’ll see what I mean)
  • the scroll bar is simply not functional. It appears locked and you can’t really drag it to scroll up and down the menu.

Here is a working fiddle.

Note I’ve tried with overflow-y: auto but it doesn’t work either.

Also, the last three links should be pushed to be bottom of the sidebar (if there is enough space). For that, I’m using margin-top: auto on the first item of the group.

HTML:

<div class="sidebar">
  <div class="sidebar-head">H</div>
  <ul class="menu">
    <li><a href="">1</a></li>
    <li><a href="">2</a></li>
    <li><a href="">3</a></li>
    <li><a href="">4</a></li>
    <li><a href="">5</a></li>
    <li><a href="">6</a></li>
    <li class="bottom"><a href="">7</a></li>
    <li><a href="">8</a></li>
    <li><a href="">9</a></li>
  </ul>
</div>

CSS:

.sidebar {
    display: flex;
    flex-direction: column;
    box-shadow: none;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    padding-top: 70px;
    width: 230px;
    overflow-x: visible;
    overflow-y: auto;
    z-index: 10;
    background-color: #222d32;
    transition: left 0.3s ease, width 0.3s ease;
    left: 0;
    width: 50px;
}

.sidebar-head {
    display: flex;
    align-items: center;
    padding: 10px;
    margin-bottom: 20px;
    color: #fff;
}

.menu {
    margin-bottom: 0;
    display: flex;
    flex-wrap: wrap;
    flex-direction: column;
    justify-content: flex-start;
    flex: 1;
    padding-bottom: 10px;
  padding-left: 0;
  list-style: none;
  overflow-x: hidden;
  overflow-y: scroll;
}

.menu > li {
  width: 100%;
}

.menu > li > a {
    position: relative;
    display: flex;
    align-items: center;
    padding: 12px 15px;
    font-size: 1.08em;
    border-left: 3px solid transparent;
    transition: border-left-color 0.3s ease, background-color 0.3s ease;
    color: #fff;
    background: #0d1214;
    border-left-color: #009688;
    text-decoration: none;
    overflow: hidden;
}

.bottom {
    margin-top: auto;
}
How to solve:

It is becaouse You have given overflow-y:scroll for the list with class menu. Changing it to overflow-y:auto will fix it.

Here’s the corrected fiddle:
fiddle

###

You’ve used Flexbox for every container. There is no need to use display: flex on the .sidebar element. Change it to display: block or remove the whole display definition and it’ll scroll.

Check it here: https://jsfiddle.net/vns3gyf7/

###

I updated .menu in your fiddle and it works.

.menu {
    margin-bottom: 0;
    padding-bottom: 10px;
  padding-left: 0;
  list-style: none;
  overflow-x: hidden;
  overflow-y: auto;
}

###

The problem was flex-wrap: wrap in .menu. As soon as I removed it, everything worked as expected.

Leave a Reply

Your email address will not be published. Required fields are marked *