[HTML 5] Styling with ARIA
HTML with ARIA
2023-09-14 09:00:50 时间
See if you can do a better job styling this button using ARIA states. One huge benefit to styling with ARIA is that it provides visual feedback that you've applied the state correctly, which can act as a safeguard when you're testing and debugging your code.
In the following code, we use js to add 'expended' class to the element. But better solution is using aria-expanded to style the element.
<button class="disclosure-button mdl-button raised" aria-expanded="false" aria-controls="content"> <span class="icon" aria-hidden="true"></span> Read More </button> <div id="content" class="disclosure-content hidden" aria-hidden="true"> <p>It turns out contestants who switch have a 2/3 chance of winning the car, while contestants who stick to their choice have only a 1/3 chance! <a href="https://en.wikipedia.org/wiki/Monty_Hall_problem">Curious to know more?</a></p> </div>
if (content.getAttribute('aria-hidden') === 'true') { content.setAttribute('aria-hidden', 'false'); content.classList.remove('hidden'); button.setAttribute('aria-expanded', 'true'); button.classList.add('expanded'); } else { content.setAttribute('aria-hidden', 'true'); content.classList.add('hidden'); button.setAttribute('aria-expanded', 'false'); button.classList.remove('expanded'); }
.disclosure-button .icon::after { content: '▶'; } .disclosure-button.expanded .icon::after { content: '▼'; } .disclosure-content.hidden { visibility: hidden; opacity: 0; } .disclosure-content { visibility: visible; opacity: 1; }
Better:
.disclosure-button[aria-expanded="false"] .icon::after { content: '▶'; } .disclosure-button[aria-expanded="true"] .icon::after { content: '▼'; } .disclosure-content[aria-hidden="true"] { visibility: hidden; opacity: 0; } .disclosure-content[aria-hidden="false"] { visibility: visible; opacity: 1; }
相关文章
- html超链接位置怎么改,如何修改HTML超链接样式?
- html中超链接使用_HTML超链接代码
- html模板代码_html模板代码下载
- HTML转word_怎么把docx转换成word
- HTML制作网页_手机制作html网页
- Extjs4.2 window加载HTML,父子页面html传参
- HTML DOM的各种宽高、偏移位置的属性总结
- 【笔记】在HTML中用meta控制浏览器默认模式
- 小鱼游戏html
- 【HTML】HTML 标签 ① ( 骨架标签 | 双标签和单标签 | 嵌套关系和并列关系 | 文档类型 | 页面语言 | 编码字符集 )
- 【HTML】HTML 表格总结 ★★★ ( 表格标签 | 行标签 | 单元格标签 | 表格标签属性 | 表头单元格标签 | 表格标题标签 | 合并单元格 )
- html 输入框大小与输入内容适配
- ORA-39322: Cannot use transportable tablespace with TIMESTAMP WITH TIME ZONE columns and different time zone version. ORACLE 报错 故障修复 远程处理
- 如何在Linux上将HTML页面转化成Png图片?
- HTML 元素
- HTML <blockquote> 标签
- HTML <dialog> 标签
- HTML <html> 标签
- 文件MySQL 使用之禅 利用HTML文件实现完美保存(mysql保存html)
- 使用MySQL和HTML打造高效的数据驱动网站(mysql与html)
- Linux环境实现HTML文件编辑(linux编辑html)
- MySQL中如何存储和检索HTML数据(mysql中html)
- HTML连接Oracle利用JavaScript即可实现(html连接oracle)
- 语句使用Oracle两个WITH语句实现数据查询(oracle两个with)
- 不用模板只用ASP+FSO生成静态HTML页的一个方法