Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrollable content in fixed flexbox sidebar

Tags:

html

css

flexbox

Somehow I can't get the scrollbar work.

https://jsfiddle.net/rafuw31g/2/

If you copy-paste the content of #scrollable somehow the flexible content overflow browser height and the #bottom disappear.

#sidebar {
  box-shadow: 1px 0 0 0 rgb(25, 25, 25);
  background-color: rgb(45, 45, 45);
  position: fixed;
  width: 250px;
  display: flex;
  min-height: 100%;
  flex-direction: column
}
#sidebar > header {
  border-bottom: 1px solid rgb(25, 25, 25);
  background: url('http://puu.sh/prf5M/2b91e2fea8.png') no-repeat 0 0 transparent;
  height: 100px;
  width: 250px;
}
#sidebar > header a {
  display: block;
  height: 100%;
  width: 100%;
  cursor: pointer;
}
#sidebar > section#top {
  background-color: rgb(25, 25, 25);
  height: 35px;
  width: 100%;
  line-height: 35px;
  text-align: center;
}
#sidebar > section#top::after {
  display: block;
  content: '';
  clear: both;
}
#sidebar > section#top a {
  float: left;
  cursor: pointer;
  width: 125px;
  color: rgb(175, 175, 175);
  text-decoration: none;
}
#sidebar > section#top a:hover {
  background-color: rgb(33, 33, 33);
  color: rgb(200, 200, 200);
}
#sidebar > section#top a:first-child,
#sidebar > section#top a:first-child:hover {
  background-color: rgb(45, 45, 45);
  color: rgb(225, 225, 225);
  cursor: default;
}
#sidebar > section#scrollable {
  overflow-x: hidden;
  overflow-y: hidden;
  flex: 1;
  min-height: 50px;
}
#sidebar > section#scrollable:hover {
  overflow-y: scroll;
}
#sidebar > section#scrollable a {
  display: block;
  height: 50px;
  line-height: 50px;
}
#sidebar > section#bottom {
  position: relative;
  width: 100%;
  bottom: 0;
  border-top: 1px solid rgb(25, 25, 25);
  text-align: center;
  padding: 10px 0;
}
<div id="sidebar">
  <header>
    <a></a>
  </header>
  <section id="top">
    <a>Tab 1</a>
    <a>Tab 2</a>
  </section>
  <section id="scrollable">
    <a>
      <span>Lorem ipsum dolor sit amet</span>
    </a>
  </section>
  <section id="bottom">
    <a>Impressum</a>
  </section>
</div>
like image 761
Devidra Avatar asked Mar 07 '26 10:03

Devidra


1 Answers

You can add a container to the scrollable area:

<section id="scrollable">
  <div class="content">
...

With style:

#sidebar > section#scrollable {
  flex: 1;
  min-height: 50px;
  position: relative;
}
#sidebar > section#scrollable:hover > .content {
  overflow-y: auto;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}

jsFiddle

like image 105
Stickers Avatar answered Mar 08 '26 23:03

Stickers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!