BEM.如何处理/ id的标签?

and*_*dko 3 label accessibility input bem

据我所知,BEM根本不使用元素id.但是在这种情况下如何处理带有/ id的标签和输入?如果不使用id,使用屏幕阅读器的人将无法获得该标签用于该输入.我对吗?

Nik*_*lov 8

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

  • @ andrey.shedko是的,当然:)如果不使用`id`属性,你无法创建可访问的应用程序.即使是创建BEM的人也在使用ID:https://yandex.com/检查他们的代码:) (2认同)