Input effect on keyboard tab -> focus, but NOT on click

前端 未结 3 1429
萌比男神i
萌比男神i 2020-12-30 08:37

When a user \'tabs over\' to an input, I want the focus effect to be normally displayed, but on click, I don\'t want it to be visible.

User hits tab

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-30 09:18

    If you use the what-input.js plugin you can apply styles specifically for keyboard users. You can use the following code to highlight a button that has been tabbed to. I've found what-input to be a reliable plugin (comes bundled with Zurb Foundation) and is currently regularly maintained.

    // scss
    body[data-whatinput="keyboard"] {
      button {
        &:focus {
          // other highlight code here
          box-shadow: 0 0 5px rgba(81, 203, 238, 1);
        }
      }
    }
    

    or

    /* vanilla css */
    body[data-whatinput="keyboard"] button:focus {
      box-shadow:  0 0 5px rgba(81, 203, 238, 1);
    }
    

提交回复
热议问题