我有一个手风琴,我正在努力使键盘易于操作。我正在使用一个input元素来跟踪用户何时单击手风琴并显示隐藏的内容,这是导致问题的原因,因为输入设置为显示:无。
是否有办法使其可访问?我仍在学习Web无障碍功能。将不胜感激任何提示!
.accordion {
width: 100%;
box-shadow: 0 12px 12px -6px rgba(0, 0, 0, 0.2);
}
.accordion input[name="panel"] {
display: none;
}
.accordion label {
position: relative;
display: block;
padding: 1em;
background: rgba(65, 64, 66, 0.8);
border-radius: 0.2em 0.2em 0 0;
width: auto;
font-size: 1.2em;
color: #fff;
letter-spacing: 0.1em;
text-transform: uppercase;
font-family: FSHumanaRegular;
margin-top: 1em;
cursor: pointer;
transition: all 0.2s cubic-bezier(0.865, 0.14, 0.095, 0.87);
}
.accordion label:after {
content: "+";
position: absolute;
right: 1em;
width: 1em;
height: 1em;
color: #eee;
text-align: center;
border-radius: 50%;
background: #fdb600;
}
.accordion label:hover {
color: #fdb600;
}
.accordion input:checked + label {
color: #fdb600;
}
.accordion input:checked + label:after {
content: "-";
line-height: 0.8em;
}
.accordion .accordion_content {
overflow: hidden;
max-height: 0px;
position: relative;
padding: 0 1.425em;
background: rgba(255, 255, 255, 0.6);
box-sizing: content-box;
transition: all 150ms cubic-bezier(0.865, 0.14, 0.095, 0.87);
}
.accordion .accordion_content .accordion_body {
line-height: 1.4em;
padding: 1.8em 0 1.5em;
}
input[name="panel"]:checked ~ .accordion_content {
max-height: 1000em;
}
<div class="accordion" id="myAccordion">
<div>
<input type="checkbox" name="panel" id="accordionContent">
<label for="accordionContent">Historical Data</label>
<div class="accordion_content">
<div class="accordion_body">
<!-- CONTENT -->
<p>Hello, world!</p>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
首先,您不应该使用复选框来折叠/展开任何元素(不好的做法)。您可以改为使用<button>
来触发/控制此功能,并在此按钮上进一步添加适当的ARIA值。
您可以查看以下ARIA属性,以帮助您进一步在可折叠元素上启用辅助功能。
aria-expanded="false"
aria-controls="collapsedElementId"
例如,Bootstrap的折叠组件实现使用以下标记来增强可访问性:https://getbootstrap.com/docs/4.1/components/collapse/#accessibility