What is sr-only in Bootstrap 3?

后端 未结 6 775
猫巷女王i
猫巷女王i 2020-11-22 09:23

What is the class sr-only used for? Is it important or can I remove it? Works fine without.

Here\'s my example:

6条回答
  •  既然无缘
    2020-11-22 10:10

    According to bootstrap's documentation, the class is used to hide information intended only for screen readers from the layout of the rendered page.

    Screen readers will have trouble with your forms if you don't include a label for every input. For these inline forms, you can hide the labels using the .sr-only class.

    Here is an example styling used:

    .sr-only {
      position: absolute;
      width: 1px;
      height: 1px;
      padding: 0;
      margin: -1px;
      overflow: hidden;
      clip: rect(0,0,0,0);
      border: 0;
    }
    

    Is it important or can I remove it? Works fine without.

    It's important, don't remove it.

    You should always consider screen readers for accessibility purposes. Usage of the class will hide the element anyways, therefore you shouldn't see a visual difference.

    If you're interested in reading about accessibility:

    • Web Accessibility Initiative (WAI)

    • MDN Accessibility documentation

提交回复
热议问题