<div class="container">
<div class="hover-container">
<h1>Underline Link Effect</h1>
<p><small>(hover over above text please)</small></p>
</div>
<p class="body-text">I made this little pen because I kept forgetting how to achieve this effect. </p>
<p class="body-text"><strong>Note:</strong> Edit <code>transform-origin</code> to change how where the animation starts. It's currently set to <code>left</code>.<br /> <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/transform-origin">Read more about this property on MDN.</a> </p>
</div>
/* the code you want is around line 45 */
@import url("https://fonts.googleapis.com/css?family=Montserrat:400,700");
* {
padding: 0;
margin: 0;
}
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body {
font-family: Montserrat, sans-serif;
height: 100%;
min-height: 100vh;
background-color: #ebf3ff;
}
.container {
display: flex;
flex-flow: column;
width: 60%;
height: 100vh;
margin: 0 auto;
align-items: center;
justify-content: center;
}
.hover-container {
text-align: center;
margin-bottom: 2em;
}
.body-text {
margin: 0.5em 0;
}
/* --- this is the code you probably want ---- */
h1 {
border-bottom: 3px solid #ff8cbc;
font-size: 3em;
transition: all 0.25s linear;
position: relative;
}
h1:before {
content: "";
display: block;
width: 100%;
height: 3px;
background-color: #61a3ff;
position: absolute;
left: 0;
bottom: -3px; /* this is to match where the border is */
transform-origin: left;
transform: scale(0);
transition: 0.25s linear;
/* will-change: transform; */
}
h1:hover:before {
transform: scale(1);
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.