HTML
<div class="avatar" data-tooltip="Thinking Cat"></div>
CSS
*, *::before, *::after {
box-sizing: border-box
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
}
.avatar {
width: 100px;
height: 100px;
border-radius: 50%;
background-image: url('https://source.unsplash.com/nKC772R_qog');
background-size: cover;
background-position: center;
position: relative;
}
.avatar::before,
.avatar::after {
--scale: 0;
--arrow-size: 10px;
--tooltip-color: #333;
position: absolute;
top: -.25rem;
left: 50%;
transform: translateX(-50%) translateY(var(--translate-y, 0)) scale(var(--scale));
transition: 150ms transform;
transform-origin: bottom center;
}
.avatar::before {
--translate-y: calc(-100% - var(--arrow-size));
content: attr(data-tooltip);
color: white;
padding: .5rem;
border-radius: .3rem;
text-align: center;
width: max-content;
max-width: 100%;
background: var(--tooltip-color);
}
.avatar:hover::before,
.avatar:hover::after {
--scale: 1;
}
.avatar::after {
--translate-y: calc(-1 * var(--arrow-size));
content: '';
border: var(--arrow-size) solid transparent;
border-top-color: var(--tooltip-color);
transform-origin: top center;
}
/* Background Styles Only */
@import url('https://fonts.googleapis.com/css?family=Raleway');
* {
font-family: Raleway;
}
.side-links {
position: absolute;
top: 15px;
right: 15px;
}
.side-link {
display: flex;
align-items: center;
justify-content: center;
text-decoration: none;
margin-bottom: 10px;
color: white;
width: 180px;
padding: 10px 0;
border-radius: 10px;
}
.side-link-youtube {
background-color: red;
}
.side-link-twitter {
background-color: #1DA1F2;
}
.side-link-github {
background-color: #6e5494;
}
.side-link-text {
margin-left: 10px;
font-size: 18px;
}
.side-link-icon {
color: white;
font-size: 30px;
}
<div class="avatar" data-tooltip="Thinking Cat"></div>
CSS
*, *::before, *::after {
box-sizing: border-box
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
}
.avatar {
width: 100px;
height: 100px;
border-radius: 50%;
background-image: url('https://source.unsplash.com/nKC772R_qog');
background-size: cover;
background-position: center;
position: relative;
}
.avatar::before,
.avatar::after {
--scale: 0;
--arrow-size: 10px;
--tooltip-color: #333;
position: absolute;
top: -.25rem;
left: 50%;
transform: translateX(-50%) translateY(var(--translate-y, 0)) scale(var(--scale));
transition: 150ms transform;
transform-origin: bottom center;
}
.avatar::before {
--translate-y: calc(-100% - var(--arrow-size));
content: attr(data-tooltip);
color: white;
padding: .5rem;
border-radius: .3rem;
text-align: center;
width: max-content;
max-width: 100%;
background: var(--tooltip-color);
}
.avatar:hover::before,
.avatar:hover::after {
--scale: 1;
}
.avatar::after {
--translate-y: calc(-1 * var(--arrow-size));
content: '';
border: var(--arrow-size) solid transparent;
border-top-color: var(--tooltip-color);
transform-origin: top center;
}
/* Background Styles Only */
@import url('https://fonts.googleapis.com/css?family=Raleway');
* {
font-family: Raleway;
}
.side-links {
position: absolute;
top: 15px;
right: 15px;
}
.side-link {
display: flex;
align-items: center;
justify-content: center;
text-decoration: none;
margin-bottom: 10px;
color: white;
width: 180px;
padding: 10px 0;
border-radius: 10px;
}
.side-link-youtube {
background-color: red;
}
.side-link-twitter {
background-color: #1DA1F2;
}
.side-link-github {
background-color: #6e5494;
}
.side-link-text {
margin-left: 10px;
font-size: 18px;
}
.side-link-icon {
color: white;
font-size: 30px;
}
Comments
Post a Comment