<header class="pen-header">
<h1>Hover effects</h1>
</header>
<div class="pen-container">
<div>
<span>01</span>
<button type="button" class="btn btn--1"><span class="btn__text">Button</span></button>
</div>
<div>
<span>02</span>
<button type="button" class="btn btn--2"><span class="btn__text">Button</span></button>
</div>
<div>
<span>03</span>
<button type="button" class="btn btn--3"><span class="btn__text">Button</span></button>
</div>
<div>
<span>04</span>
<button type="button" class="btn btn--4"><span class="btn__text">Button</span></button>
</div>
<div>
<span>05</span>
<button type="button" class="btn btn--5"><span class="btn__text">Button</span></button>
</div>
<div>
<span>06</span>
<button type="button" class="btn btn--6"><span class="btn__text">Button</span></button>
</div>
</div>
<footer class="pen-footer">
<p>Template design: <a href="https://www.behance.net/barrud" target="_blank">Barrud</a> | Code: <a href="https://crocoder.pl" target="_blank">CroCoder</a></p>
</footer>
$font-main: 'Poppins', sans-serif;
$font-code: 'Source Code Pro', monospace;
$color-light-dark: #ebebeb;
$color-dark: #232426;
$color-red: #e4562a;
$btn-width: 180px;
$btn-height: 45px;
$time: 0.3s;
html{ box-sizing: border-box; }
*, *:before, *:after{ box-sizing: inherit; }
html, body{ width: 100%; }
body{
font-family: $font-main;
color: $color-dark;
padding: 5%;
}
h1{
position: relative;
text-align: center;
font-size: 36px;
line-height: 1;
&::before{
position: absolute;
left: 50%;
transform: translateX(-50%);
bottom: -12px;
z-index: -1;
color: $color-light-dark;
content: "Button";
font-size: 3em;
}
}
.pen-container{
display: flex;
flex-direction: column;
flex-wrap: wrap;
align-items: center;
width: 300px;
max-width: 450px;
margin: 0 auto;
padding: 5%;
background-color: $color-light-dark;
& > div{
width: $btn-width;
padding: 40px 0;
& >span{
display: block;
margin-bottom: 2em;
font-size: 14px;
font-family: $font-code;
}
}
}
/**
* Base
*/
.btn{
position: relative;
border: 0;
padding: 0;
width: $btn-width;
height: $btn-height;
cursor: pointer;
&__text{
font-size: 14px;
text-transform: uppercase;
font-weight: 700;
color: #fff;
}
}
/**
* Button 01
*/
.btn--1{
background: $color-dark;
.btn__text{
position: relative;
z-index: 1;
}
&::before, &::after{
position: absolute;
top: 0;
display: block;
height: 100%;
width: 0;
background-color: $color-red;
content: "";
}
&::before{
left: 0;
}
&::after{
right: 0;
transition: width $time;
}
&:hover::before{
width: 100%;
transition: width $time;
}
&:hover::after{
background-color: transparent;
width: 100%;
}
}
/**
* Button 02
*/
.btn--2{
background: $color-dark;
overflow: hidden;
.btn__text{
position: absolute;
top: 0;
left: 0;
display: inline-block;
width: 100%;
height: 100%;
line-height: $btn-height;
transition: top $time;
}
&::after{
position: absolute;
top: 100%;
left: 0;
display: block;
width: 100%;
height: 100%;
line-height: $btn-height;
background-color: $color-red;
content: "Click!";
transition: top $time;
font-size: 14px;
font-weight: 700;
color: #fff;
text-transform: uppercase;
}
&:hover::after{ top: 0; }
&:hover > .btn__text{ top: -100%; }
}
/**
* Button 03
*/
.btn--3{
background: transparent;
.btn__text{
position: relative;
z-index: 1;
color: $color-dark;
transition: color $time;
}
&::after{
position: absolute;
top: calc(100% - 2px);
left: 0;
display: block;
height: 2px;
width: 100%;
content: "";
background-color: $color-red;
transition: all $time;
}
&:hover::after{
top: 0;
height: 100%;
}
&:hover .btn__text{
color: #fff;
}
}
/**
* Button 04
*/
.btn--4{
background-color: $color-dark;
.btn__text{
position: relative;
z-index: 1;
}
&::after{
position: absolute;
top: 0;
left: 0;
display: block;
width: 100%;
height: 100%;
content: "";
}
&::after{
background-color: $color-dark;
transition: all $time;
}
&:hover::after{
background-color: $color-red;
transform: scale(1.1);
}
}
/**
* Button 05
*/
.btn--5{
background-color: $color-dark;
.btn__text{
position: relative;
z-index: 1;
}
&::after{
position: absolute;
top: 0;
left: 0;
display: block;
width: 100%;
height: 100%;
content: "";
transition: all $time;
}
&::after{
background-color: $color-red;
transform: scale(0.5);
opacity: 0;
}
&:hover::after{
opacity: 1;
transform: scale(1);
}
}
/**
* Button 06
*/
.btn--6{
background-color: transparent;
.btn__text{
position: relative;
z-index: 1;
color: $color-dark;
}
&::before, &::after{
position: absolute;
bottom: 0;
display: block;
height: 50%;
width: 0;
background-color: $color-red;
content: "";
}
&::before{
left: 0;
}
&::after{
right: 0;
transition: width $time;
}
&:hover::before{
width: 100%;
transition: width $time;
}
&:hover::after{
background-color: transparent;
width: 100%;
}
}
.pen-footer{
margin-top: 50px;
font-size: 14px;
text-align: center;
}
@media all and (min-width: 768px){
.pen-container{
flex-direction: row;
justify-content: space-between;
width: 100%;
max-width: 740px;
}
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.