【问题标题】:How to Place text content within the <button> element or give the <input> element a value attribute如何在 <button> 元素中放置文本内容或为 <input> 元素赋予 value 属性
【发布时间】:2021-07-11 15:56:05
【问题描述】:

在 wordpress 网站上的 wcag 可访问性问题上,我需要您的帮助,使用 wave 检查网站会返回两个基本错误“按钮为空或没有值文本”。对于两个切换菜单,wave 修复错误的建议是“在元素中放置文本内容或给元素一个值属性。”

但我不知道如何解决这个问题,我的切换按钮的代码是:

<button class="btn-close-form" data-toggle-target=".search-modal" data-toggle-body-class="showing-search-modal" data-set-focus=".search-modal .search-field" aria-expanded="false"> <span></span> </button>

因此,如果有人知道如何将文本或替代文本分配给切换按钮以解决此问题,那就太好了。

感谢大家的宝贵时间!!!

【问题讨论】:

  • 在你的开始按钮标签和结束按钮标签之间只有一个空的span元素......没有描述按钮是什么的文字。
  • 您好 Zachary,感谢您的回答和帮助,所以我应该尝试插入类似 input alt="text" 的内容吗? ,对不起,如果我的答案似乎很愚蠢,但我真的不知道要修改什么?再次感谢兄弟!!!!!!
  • 它在建议中说 - “......或者给元素一个值属性”。

标签: wcag


【解决方案1】:

1 - 您可以在其中添加文本并将其隐藏在 CSS 中。 WordPress为此提供了特殊的class - screen-reader-text

// CSS

/* Text meant only for screen readers. */
.screen-reader-text {
  border: 0;
  clip: rect(1px, 1px, 1px, 1px);
  clip-path: inset(50%);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
  word-wrap: normal !important;
}
.screen-reader-text:focus {
  background-color: #eee;
  clip: auto !important;
  clip-path: none;
  color: #444;
  display: block;
  font-size: 1em;
  height: auto;
  left: 5px;
  line-height: normal;
  padding: 15px 23px 14px;
  text-decoration: none;
  top: 5px;
  width: auto;
  z-index: 100000; /* Above WP toolbar. */
}
// button
<button class="btn-close-form" data-toggle-target=".search-modal" data-toggle-body-class="showing-search-modal" data-set-focus=".search-modal .search-field" aria-expanded="false"> 
<span></span>
<span class="screen-reader-text">Show search modal</span> 
</button>

这个类在视觉上对用户隐藏元素,但可以用屏幕阅读器阅读。该元素在聚焦时可见

2 - 添加aria-labelaria-labelledby 属性

<button class="btn-close-form" data-toggle-target=".search-modal" data-toggle-body-class="showing-search-modal" data-set-focus=".search-modal .search-field" aria-expanded="false" aria-label="Show search modal"> 
<span></span>
</button>

// or
<span id="show-modal-label">Show search modal</span>

<button class="btn-close-form" data-toggle-target=".search-modal" data-toggle-body-class="showing-search-modal" data-set-focus=".search-modal .search-field" aria-expanded="false" aria-labelledby="show-modal-label"> 
<span></span>
</button>

【讨论】:

  • 成功了!!!!!!非常感谢兄弟,感谢您的时间和宝贵的帮助,与此同时,我还尝试输入 function.php,其中代码按钮位于类似的位置: 也可以,但是文本没有正确对齐
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-09-10
  • 1970-01-01
  • 2015-05-06
  • 1970-01-01
  • 2021-03-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多