[HTML5] Add Semantic Styling to the Current Page of a Navigation Item with aria-current
2024-09-01 14:28:19
In this lesson, we are going to use aria-current to give a screen reader user more context about what the current page is. Historically, many developers use an .active
class to indicate that the page in a menu is the same that you're on.
Instead of using a class, we are going to use the aria-current attribute to add more semantic value to the HTML and use that attribute to style the active link.
Note: VoiceOver testing works best on the Native Safari Browser, hence why we should always use Safari to test.
More resources:
- Using the aria current attribute
- W3 WAI-ARIA - aria-current
- Breadcrumb Example - w3-WAI ARIA Practices
<nav>
<ul class="menu">
<li class="menu__item">
<a href="/" class="menu__link" aria-current="page">Home</a>
</li>
<li class="menu__item">
<a href="/" class="menu__link">About</a>
</li>
<li class="menu__item">
<a href="/" class="menu__link">News</a>
</li>
<li class="menu__item">
<a href="/" class="menu__link">Contact</a>
</li>
</ul>
</nav>
.menu {
display: flex;
padding:;
list-style: none; .menu__link {
display: inline-block;
position: relative;
text-transform: uppercase;
font-weight: bold;
color: #6505cc;
padding: 0.675rem;
margin: 0 0.5rem;
font-size: 1.5rem;
text-decoration: none; &[aria-current="page"] {
border-bottom: 8px solid #6505cc;
}
}
}
最新文章
- [LeetCode] Power of Three 判断3的次方数
- 微信小程序产品定位及功能介绍
- 避免在ASP.NET Core中使用服务定位器模式
- iOS中Objective-C与JavaScript之间相互调用的实现(实现了与Android相同的机制)转
- 1029c语言文法定义与c程序的推导过程
- C# 给数据库传入当前时间
- Zigzag Iterator 解答
- 【Android基础】Activity之间进行参数传递的三种方式
- asp.net webForm 前后台类关系
- 【原创】Superset在windows下的安装配置
- mac mono Fiddler.exe启动失败
- 如何用Visio画venn(维恩)图
- Java中三种代理模式
- BZOJ4241历史研究——回滚莫队
- <;六>;企业级开源仓库nexus3实战应用–使用nexus3配置yum私有仓库
- 我所理解Java集合框架的部分的使用(Collection和Map)
- Lepus监控之Oracle配置
- Android NDK之二:创建NativeActivity
- Elasticsearch工作原理
- Buffer I/O error on device sr0