<nav>
<a href="#" id="home" class="active">Home</a>
<a href="#" id="dashboard">Dashboard</a>
<a href="#" id="profile">Profile</a>
<a href="#" id="notifications" data-count="1">Notifications</a>
<a href="#" id="settings">Settings</a>
</nav>
<main>
<div class="hint">
<p>Hover over any link, and the other links will be blurred out. <br />
Additionally, the notification count will automatically increase for the demo.</p>
</div>
<div class="credits">
© 2024 - Gaurav Sachdeva
<a href="https://redirect.gauravsachdeva.in?page=blog" target="_blank">Blog</a> |
<a href="https://redirect.gauravsachdeva.in?page=codepen" target="_blank">CodePen</a> |
<a href="https://redirect.gauravsachdeva.in?page=github" target="_blank">Github</a>
</div>
</main>
@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans&display=swap");
* {
font-family: "IBM Plex Sans", system-ui, sans-serif;
box-sizing: border-box;
}
body {
display: flex;
background: gainsboro;
font-size: large;
margin: 3.5rem 0.5rem;
flex-direction: column;
text-align: center;
}
nav {
display: flex;
background-color: #e7e7e7;
margin: 0 auto;
padding: 0rem 0.55rem;
border: 2px solid #bbb;
border-radius: 1rem;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
nav a {
display: inline-block;
color: #333;
text-decoration: none;
padding: 1rem 1.5rem;
margin: 0;
border: 2px solid #bbb;
border-width: 0 1px;
transition: all 0.3s ease;
}
nav a:first-child {
border-left: 0;
}
nav a:last-child {
border-right: 0;
}
nav a.active {
font-weight: bold;
}
nav a:hover {
background-color: #ddd;
border-radius: 0.5rem;
}
nav:hover a:not(:hover) {
opacity: 0.5;
color: transparent;
text-shadow: 0 0 0.25rem #000;
}
a[data-count]:after {
content: attr(data-count);
display: inline-flex;
align-items: center;
justify-content: center;
margin-left: 0.2rem;
background-color: darkgreen;
color: white;
border-radius: 50%;
width: 1.5rem;
height: 1.5rem;
font-size: 0.75rem;
font-weight: bold;
position: relative;
top: -0.15rem;
}
a.alert[data-count]:after {
background-color: maroon;
}
main {
margin: 3rem;
}
main .credits,
main .credits a {
margin-top: 5rem;
color: #555;
}
let timer = setInterval(increaseNotificationCnt, 2500);
function increaseNotificationCnt() {
const notifications = document.querySelector("a#notifications");
const count = parseInt(notifications.getAttribute("data-count") || 0);
const newCount = count + 1;
notifications.setAttribute("data-count", newCount);
if (newCount > 10) notifications.classList.add("alert");
if (newCount > 30) clearInterval(timer);
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.