Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrollbar "jumps" to another location with scrollable container when checkbox is clicked

Tags:

html

css

Here's my fiddle:

https://jsfiddle.net/85ef12m9/

I have this class

.scrollable{
    overflow: auto;
    max-height:400px;
}

and I have say a very long div with many elements:

<div class=scrollable>
  <div>
     <input type="checkbox" id="test0" />
     <label for="test0">Red</label>
  </div>
  <div>
     <input type="checkbox" id="test1" />
     <label for="test1">Red</label>
  </div>
  ....

When I click on an element say test51 my scrollbar jumps down to the element location as if it was not contained within the scrollable div. Any one has any idea why this is happening?

like image 902
Stupid.Fat.Cat Avatar asked Nov 02 '16 19:11

Stupid.Fat.Cat


1 Answers

Turns out the answer is simple, simply add:

.scrollable{
    position: relative;
}

https://jsfiddle.net/161pnkzr/1/

I've also fixed your closing </div>'s in the jsfiddle (they were <div/> originally).

Reference: https://github.com/Dogfalo/materialize/issues/992

like image 170
Eugene Avatar answered Oct 16 '22 05:10

Eugene