Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Element using overflow: scroll has scrollbar going off screen

Tags:

html

css

html, body {
  min-height: 100%;
  margin: 0;
  padding: 0;
  overflow-y: hidden;
}

#sidebar {
  background-color: white;
  height: 100%;
  width: 20%;
  float: left;
  position: fixed;
  box-shadow: 0px 1px 5px rgba(0, 0, 0, 0.5);
  padding-bottom: 6em;
  overflow-x: scroll;
}

The sidebar has a scroll which moves approximately 50px off the screen, please refer to image provided. I have tried using padding or margin on both body and #sidebar, to no avail.

scroll going off screen

like image 869
Nick Tucci Avatar asked Jul 24 '26 03:07

Nick Tucci


1 Answers

Because you have no set height on #sidebar's container, 100% height will be auto. The scrollbar will be the size of it's container (#sidebar) so it will just stretch. Try something like this:

#sidebar {
  top: 0;
  bottom: 0;
}

You could also use window units:

#sidebar {
  height: 100vh;
}
like image 138
Will Reese Avatar answered Jul 25 '26 17:07

Will Reese



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!