A Pen by Trung Dang on CodePen.
Created
September 14, 2023 15:14
-
-
Save hanguyen1406/485b2aab23bd4c8e809a4b4d5f8a4430 to your computer and use it in GitHub Desktop.
Floating Action Button with Popup Menu [ELEMENTS]
This file contains 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
<div class="wrapper"> | |
<input type="checkbox" /> | |
<div class="fab"></div> | |
<div class="fac"> | |
<a href="#"><i class="fas fa-suitcase"></i></a> | |
<a href="#"><i class="far fa-file-alt"></i></a> | |
<a href="#"><i class="fas fa-wallet"></i></a> | |
</div> | |
</div> |
This file contains 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
:root { | |
--background: #4285f4; | |
--icon-color: #344955; | |
--width: 50px; | |
--height: 50px; | |
--border-radius: 100%; | |
} | |
body { | |
background: #fff; | |
background-color: #eff8e2; | |
height: 100vh; | |
font: "Lexend Deca", sans-serif; | |
display: flex; | |
flex-direction: column; | |
justify-content: center; | |
align-items: center; | |
overflow: hidden; | |
margin: 0; | |
padding: 0; | |
} | |
.wrapper { | |
width: var(--width); | |
height: var(--height); | |
position: relative; | |
border-radius: var(--border-radius); | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
margin-top: 6rem; | |
.fab { | |
background: var(--background); | |
width: var(--width); | |
height: var(--height); | |
position: relative; | |
z-index: 3; | |
border-radius: var(--border-radius); | |
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4); | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
animation: fab-animation-reverse 0.4s ease-out forwards; | |
&::before, | |
&::after { | |
content: ""; | |
display: block; | |
position: absolute; | |
border-radius: 4px; | |
background: #fff; | |
} | |
&::before { | |
width: 4px; | |
height: 18px; | |
} | |
&::after { | |
width: 18px; | |
height: 4px; | |
} | |
} | |
.fac { | |
//floating actions container | |
width: 32px; | |
height: 150px; | |
border-radius: 64px; | |
position: absolute; | |
background: #fff; | |
z-index: 2; | |
padding: 0.5rem 0.5rem; | |
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4); | |
opacity: 0; | |
top: -110px; | |
display: flex; | |
flex-direction: column; | |
justify-content: space-around; | |
align-items: center; | |
transition: opacity 0.2s ease-in, top 0.2s ease-in, width 0.1s ease-in; | |
/*&::after { | |
content: ""; | |
width: 20px; | |
height: 20px; | |
background: #fff; | |
border-radius: 3px; | |
position: absolute; | |
left: 50%; | |
margin-left: -10px; | |
bottom: -8px; | |
transform: rotate(45deg); | |
z-index: 0; | |
}*/ | |
a { | |
color: var(--icon-color); | |
opacity: 0.8; | |
&:hover { | |
transition: 0.2s; | |
opacity: 1; | |
color: darken(#344955, 2%); | |
} | |
} | |
} | |
input { | |
height: 100%; | |
width: 100%; | |
border-radius: var(--border-radius); | |
cursor: pointer; | |
position: absolute; | |
z-index: 5; | |
opacity: 0; | |
&:checked { | |
~ .fab { | |
animation: fab-animation 0.4s ease-out forwards; | |
} | |
~ .fac { | |
width: 32px; | |
height: 150px; | |
animation: fac-animation 0.4s ease-out forwards 0.1s; | |
top: -180px; | |
opacity: 1; | |
} | |
} | |
} | |
} | |
@keyframes fab-animation { | |
0% { | |
transform: rotate(0) scale(1); | |
} | |
20% { | |
transform: rotate(60deg) scale(0.93); | |
} | |
55% { | |
transform: rotate(35deg) scale(0.97); | |
} | |
80% { | |
transform: rotate(48deg) scale(0.94); | |
} | |
100% { | |
transform: rotate(45deg) scale(0.95); | |
} | |
} | |
@keyframes fab-animation-reverse { | |
0% { | |
transform: rotate(45deg) scale(0.95); | |
} | |
20% { | |
transform: rotate(-15deg); | |
} | |
55% { | |
transform: rotate(10deg); | |
} | |
80% { | |
transform: rotate(-3deg); | |
} | |
100% { | |
transform: rotate(0) scale(1); | |
} | |
} | |
@keyframes fac-animation { | |
0% { | |
transform: scale(1, 1); | |
} | |
33% { | |
transform: scale(0.95, 1.05); | |
} | |
66% { | |
transform: scale(1.05, 0.95); | |
} | |
100% { | |
transform: scale(1, 1); | |
} | |
} |
This file contains 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://pro.fontawesome.com/releases/v5.2.0/css/all.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment