<nav class="menu">
<a href="#" class="menu__item" data-tooltip="Dashboard">
<i class="material-icons">home</i>
</a>
<a href="#" class="menu__item menu__item--active" data-tooltip="Music Library">
<i class="material-icons">music_note</i>
</a>
<a href="#" class="menu__item" data-tooltip="Statistics">
<i class="material-icons">timeline</i>
</a>
<a href="#" class="menu__item" data-tooltip="Account Security">
<i class="material-icons">https</i>
</a>
<a href="#" class="menu__item" data-tooltip="Settings">
<i class="material-icons">settings</i>
</a>
</nav>
<h1>contents here</h1>
html {
/* set space for menu to appear, or everything in html will covered 75px by menu */
margin-left: 75px;
}
.menu {
position: fixed;
top: 0;
left: 0;
width: 75px;
height: 100%;
background: #eeeeee;
font-size: 16px;
font-family: sans-ferif;
}
.menu__item {
position: relative;
display: flex;
justify-content: center;
align-items: center;
padding: 15px 0;
text-decoration: none;
color: #666666;
transition: background 0.3s;
}
.menu__item > i {
font-size: 2.2em; /* 2.2*16px */
}
.menu__item--active {
color: #000000;
background: #dddddd;
}
.menu__item:hover {
background: #dddddd;
}
/* create tooltip after each menu item */
.menu__item::after {
position: absolute;
display: inline-block; /* ::before, ::after are inline as default
/* makes tooltip vertically center within each one of menu items */
top: 50%;
transform: translateY(-50%);
/* starting tooltip 100% left of menu item (just the right of them) */
left: 100%;
/* linked to the HTML attribute value */
/* 使用 ::before 和 ::after 一定要有 content 否則不會發生作用。 */
content: attr(data-tooltip);
/* set margin between menu item and tooltip */
margin-left: 15px;
/* makes words in same line */
white-space: nowrap;
padding: 7px 12px;
/* 90% of current font size */
font-size: 0.9em;
font-weight: bold;
background: rgba(0, 0, 0, 0.8);
border-radius: 15px;
color: #fff;
/* invisible (can't see it but can click on it) */
opacity: 0;
/* can't click */
visibility: hidden;
transition: opacity 1s;
}
/* show tooltip if hover on menu item */
.menu__item:hover::after {
opacity: 1;
visibility: visible;
}
This Pen doesn't use any external JavaScript resources.