CSS Notification Badge

Web Design & Web Development

Demo

Sponsored links

 

Code

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>CSS Notification Badge</title>
    <link rel="stylesheet" type="text/css" href="https://demo.plantpot.works/assets/css/normalize.css">
    <link rel="stylesheet" href="https://use.typekit.net/opg3wle.css">
    <link rel="stylesheet" type="text/css" href="style.css">
  </head>
  <body>
    <div id="container">
      <a class="notifications" href="#">
        <img src="ic_notifications.svg" alt="">
        <span class="badge">10</span>
      </a>
      <h1>CSS Notification Badge</h1>
    </div>
  </body>
</html>

CSS

@charset "utf-8";
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  font-size: 16px;
}
body {
  background-color: #dedede;
  font-family: futura-pt, sans-serif;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
}
#container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100vh;
  padding: 20px;
}
.notifications {
  position: relative;
}
.notifications:hover {
  opacity: .8;
}
.notifications img {
  width: 100px;
}
.notifications .badge {
  display: flex;
  justify-content: center;
  align-items: center;
  position: absolute;
  top: 0;
  right: 0;
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border-radius: 18px;
  background-color: #e60323;
  color: #fff;
  font-size: 1rem;
}
h1 {
  margin: 20px 0;
  color: #3d3935;
  font-size: 2.5rem;
  letter-spacing: 1px;
  text-align: center;
}
@media screen and (max-width: 480px) {
  #container {
    height: auto;
  }
  h1 {
    font-size: 2rem;
  }
}