DEV Community

Cover image for Notification Panel
Jatin Sharma
Jatin Sharma

Posted on • Updated on

Notification Panel

In this article, we are going to build a notification panel style with CSS and will toggle the button with JS. It's very simple to do, just follow the below code.

Preview

preview

Requirements-

To get all the icons you can Sign Up to the FontAwesome. It has various types of icons that are free to use, you can also upgrade to the paid version if needed.

HTML



<div class="container">
  <button class="icon">
    <i class="fas fa-wifi"></i>
  </button>
</div>


Enter fullscreen mode Exit fullscreen mode

I'm showing just a single icon button (.icon), but there are more than just one. And you can add as many you want.

CSS



:root {
  --icon-bg: #212121;
  --icon-fg: gray;
}

* {
  margin: 0;
  padding: 0;
}

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.icon {
  all: unset; /* removing all the pre defined style */
  font-size: 1.4rem;
  width: 40px;
  height: 40px;
  padding: 0.5rem;
  border-radius: 999px;

  display: grid; /* making icon center horizontally and vertically */
  place-items: center;

  background: var(--icon-bg);
  color: var(--icon-fg);
  border: 2px solid transparent;

  transition: background 200ms ease-in-out;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent; /* Removing Blue Highlight box */
}

/* To Prevent Hover on smaller Devices */
@media screen and (min-width: 500px) {
  .icon:hover {
    border: 2px solid white;
    box-shadow: 0 0 20px -5px white;
  }
}
/* Change the bg and fg */
.active-icon {
  --icon-bg: white;
  --icon-fg: black;
}


Enter fullscreen mode Exit fullscreen mode

Javascript



const icons = document.querySelectorAll(".icon");
// Adding an event listener to the icons to change the active status
icons.forEach((icon) =>
  icon.addEventListener("click", () => {
    icon.classList.toggle("active-icon");
  })
);



Enter fullscreen mode Exit fullscreen mode

codepen

Wrapping Up

If you enjoyed this article then don't forget to press ❤️. If you have any queries or suggestions don't hesitate to drop them. See you.

You might be interested in -

Top comments (0)