and*_*dko 3 label accessibility input bem
据我所知,BEM根本不使用元素id.但是在这种情况下如何处理带有/ id的标签和输入?如果不使用id,使用屏幕阅读器的人将无法获得该标签用于该输入.我对吗?
BEM建议避免id
使用css选择器.它非常适用id
于A11y和可用性.
<form class="form" method="post" action="">
<label for="email" class="form__label">Email</label>
<input type="email" id="email" class="form__control"/>
</form>
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,我们将输入样式化为form
具有form__control
类的块的元素.
此外,如果没有id
指向描述性元素的指针,则不能使用aria属性.
<div role="application" aria-labelledby="calendar" aria-describedby="info">
<h1 id="calendar">Calendar</h1>
<p id="info">
This calendar shows the game schedule for the Boston Red Sox.
</p>
<div role="grid">
...
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
示例取自:https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-describedby_attribute