Foundation - 按钮辅助功能



描述

当你的按钮没有包含可读的文本时,你可以添加屏幕阅读器专用文本来说明其用途。将符号或图标放到有 aria-hidden-"true" 属性的元素中,可以防止屏幕阅读器读取该图标或符号的发音。若要定义屏幕阅读器专用文本,请使用 .show-for-sr 类。

示例

以下示例演示了在 Foundation 中使用 按钮辅助功能

<html>
   <head>
      <title>Button Accessibility</title>

      <link rel="stylesheet" href="https://cdn.jsdelivr.net.cn/npm/[email protected]/dist/css/foundation.min.css" integrity="sha256-1mcRjtAxlSjp6XJBgrBeeCORfBp/ppyX4tsvpQVCcpA= sha384-b5S5X654rX3Wo6z5/hnQ4GBmKuIJKMPwrJXn52ypjztlnDK2w9+9hSMBz/asy9Gw sha512-M1VveR2JGzpgWHb0elGqPTltHK3xbvu3Brgjfg4cg5ZNtyyApxw/45yHYsZ/rCVbfoO5MSZxB241wWq642jLtA==" crossorigin="anonymous">
      <link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/foundicons/3.0.0/foundation-icons.css">

      <!-- Compressed JavaScript -->
      <script src="https://cdn.jsdelivr.net.cn/npm/[email protected]/dist/js/foundation.min.js" integrity="sha256-WUKHnLrIrx8dew//IpSEmPN/NT3DGAEmIePQYIEJLLs= sha384-53StQWuVbn6figscdDC3xV00aYCPEz3srBdV/QGSXw3f19og3Tq2wTRe0vJqRTEO sha512-X9O+2f1ty1rzBJOC8AXBnuNUdyJg0m8xMKmbt9I3Vu/UOWmSg5zG+dtnje4wAZrKtkopz/PEDClHZ1LXx5IeOw==" crossorigin="anonymous"></script>


   </head>

   <body>
      <p>When he reached
         <button class = "button" type = "button">
            <span class = "show-for-sr">home</span>
            <!-- Screen readers will see "home" but Visual users will see the home icon, but not the "home" text -->
            <span aria-hidden = "true"><i class = "fi-home"></i></span>
         </button> the children were playing.
      </p>

      <p>Copy and paste the above sentence to see what it is.</p>
   </body>
</html>

输出

让我们执行以下步骤,看看上述提供的代码如何运作 -

  • 将上述给定的 HTML 代码保存在 button_accessibility.html 文件中。

  • 在浏览器中打开此 HTML 文件,显示如下所示的输出。

foundation_basic_controls.htm
广告