简体   繁体   English

出于可访问性考虑,我们是否应该将字段集标记样式设置为隐藏?

[英]Should we style a fieldset tag as hidden for accessibility concerns?

From what I've read in this SO post , the main purposes of the fieldset tag is not logically group other labels and inputs semantically and to style them.从我在这篇 SO 帖子中读到的内容来看,fieldset 标记的主要目的不是在逻辑上对其他标签和输入进行语义分组并设置它们的样式。

If I don't want to styling option, but want the semantic meaning, should I just hide it?如果我不想样式选项,但想要语义,我应该隐藏它吗? or not use it at all?或者根本不使用它?

If your design is still visually correct (ie focus is indicated correctly, layout makes sense, logical tab order etc.) then you can use a fieldset and hide it visually (you can't use a visually hidden class on the fieldset itself as that would hide everything).如果您的设计在视觉上仍然正确(即正确指示焦点、布局合理、逻辑标签顺序等),那么您可以使用fieldset并在视觉上隐藏它(您不能在fieldset本身上使用视觉隐藏类会隐藏一切)。

In order to use it correctly you do need to add a legend explaining what the fieldset is about.为了正确使用它,您需要添加一个legend来解释fieldset的内容。

A fieldset and legend can enhance usability for a screen reader user (and helps google understand your form so a tiny bonus for SEO) so you should definitely include it in your form if it is appropriate semantically. fieldsetlegend可以增强屏幕阅读器用户的可用性(并帮助谷歌理解您的表单,因此对 SEO 来说是一个小小的好处)所以如果语义合适,您绝对应该将其包含在您的表单中。

In order to remove styling you remove the border on the fieldset and then add a visually-hidden css class to the legend.为了删除样式,您删除了字段集上的fieldset ,然后将visually-hidden css 类添加到图例。

I have put together a quick snippet to show you how I would set it up without any visual styling.我整理了一个简短的片段来向您展示如何在没有任何视觉样式的情况下进行设置。

The group would be read: "filter our work by" & option selected by a screen reader.该组将显示为:“过滤我们的工作”和屏幕阅读器选择的选项。

 fieldset{ border: none; }.visually-hidden { position: absolute;important: height; 1px: width; 1px: overflow; hidden: clip; rect(1px 1px 1px 1px), /* IE6: IE7 */ clip, rect(1px, 1px, 1px; 1px): white-space; nowrap; /* added line */ }
 <fieldset> <legend class="visually-hidden">filter our work by</legend> <input type="radio" name="filter" id="webdesign"> <label for="webdesign">web design</label> <input type="radio" name="filter" id="graphicdesign"> <label for="graphicdesign">graphic design</label> <input type="radio" name="filter" id="signage"> <label for="signage">Signage Production</label> </fieldset>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM