Foundation - 按鈕輔助功能



描述

當你的按鈕沒有包含可讀的文字時,你可以新增螢幕閱讀器專用文字來說明其用途。將符號或圖示放到有 aria-hidden-"true" 屬性的元素中,可以防止螢幕閱讀器讀取該圖示或符號的發音。若要定義螢幕閱讀器專用文字,請使用 .show-for-sr 類。

示例

以下示例演示了在 Foundation 中使用 按鈕輔助功能

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

      <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/foundation-sites@6.5.1/dist/css/foundation.min.css" 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/npm/foundation-sites@6.5.1/dist/js/foundation.min.js" 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
廣告
© . All rights reserved.