Created
May 1, 2017 04:04
-
-
Save CodeMyUI/74ca40ea7bc9a674636ea311b37a8c7b to your computer and use it in GitHub Desktop.
Animated CSS Tooltip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form> | |
<input type="text" placeholder="username"/> | |
<div id="anim"> | |
<span class="tooltip" data-tooltip="username must consist of 29 symbols.">?</span> | |
</form> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$pink: #ff3466; | |
@import url('https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400'); | |
body { | |
background: #424B54; | |
font-family: 'Source Sans Pro', sans-serif; | |
overflow: hidden; | |
} | |
form { | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
position: relative; | |
width: 100%; | |
height: 100vh; | |
} | |
input { | |
border: none; | |
width: 170px; | |
height: 25px; | |
outline: none; | |
padding-left: 10px; | |
} | |
.tooltip { | |
position: relative; | |
background: $pink; | |
padding: 5px 12px; | |
margin: 5px; | |
font-size: 15px; | |
border-radius: 100%; | |
color: #FFF; | |
} | |
.tooltip:before, | |
.tooltip:after { | |
position: absolute; | |
content: ''; | |
opacity: 0; | |
transition: all 0.4s ease; | |
} | |
.tooltip:before { | |
border-width: 10px 8px 0 8px; | |
border-style: solid; | |
border-color: $pink transparent transparent transparent; | |
top: -15px; | |
transform: translateY(20px); | |
} | |
.tooltip:after { | |
content: attr(data-tooltip); | |
background: $pink; | |
width: 160px; | |
height: 40px; | |
font-size: 13px; | |
font-weight: 300; | |
top: -75px; | |
left: -10px; | |
padding: 10px; | |
border-radius: 5px; | |
letter-spacing: 1px; | |
transform: translateY(20px); | |
} | |
.tooltip:hover::before, | |
.tooltip:hover::after { | |
opacity: 1; | |
transform: translateY(-2px); | |
} | |
@keyframes shake { | |
0% { | |
transform: rotate(2deg); | |
} | |
50% { | |
transform: rotate(-3deg); | |
} | |
70% { | |
transform: rotate(3deg); | |
} | |
100% { | |
transform: rotate(0deg); | |
} | |
} | |
#anim:hover { | |
animation: shake 500ms ease-in-out forwards; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment