How can I prevent the browser from scrolling on top of the page when clicking the checkbox?

前端 未结 3 1697
Happy的楠姐
Happy的楠姐 2020-12-16 17:46

Whenever I click on the checkbox, the browser window (firefox) will scroll on the top of the screen.
How can I prevent this behavior so when I click on the checkbox the

3条回答
  •  旧巷少年郎
    2020-12-16 18:20

    The answer accepted is not entirely true. Works, but not in all cases.

    If you use the common css to hide elements (probably -999em or similar) at the "top" attribute, in this case position:relative has nothing to do because always -999em will be much higher than the viewport.

    The answer accepted works fine because the "top" is only -20px . Try to set it a more higher number and you´ll see the problem.

    So, the solution is not to set a relative position. I think the correct way is only to set a negative value at left position (not top).

    Try it. :)

提交回复
热议问题