Radio button causes browser to jump to the top

后端 未结 5 553
甜味超标
甜味超标 2021-02-05 14:48

Problem:

When clicking on a label (for a radio button that has been intentionally hidden by positioning it off-screen), the browser undesirably jumps to the top of the

5条回答
  •  星月不相逢
    2021-02-05 15:12

    Here's what I did, and it worked well and still allowed for accessibility.

    .hiddenInput {
      opacity: 0;
      height: 0;
      width: 0;
      margin: 0;
      padding: 0;
      position: fixed;
      top: 0;
    }
    

    That way the input is always in "view" so the label never has to forcibly scroll to it. The 'top: 0' is optional, for me it defaulted to the middle of my screen, I just put it somewhere explicitly.

提交回复
热议问题