Github repository: github.com/kevinsunny2…
Github page: kevinsunny2008.github.io/animated-na…
- Resources:
How to use color variables in CSS
developer.mozilla.org/en-US/docs/…
Color scheme to find similar colors paletton.com/#uid=1000u0…
Menu icon from W3C School www.w3schools.com/howto/howto…
Animation in CSS developer.mozilla.org/en-US/docs/…
- Variables in the CSS
Declaring variable in the CSS, use double dash at the begining of the variable names
:root {
--primaryColor: #fff;
--navColor1: #21292c;
--navColor2: #aa3e39;
--navColor3: #aa6e39;
--navColor4: #236267;
--navColor5: #2c8437;
}
The :root CSS pseudo-class matches the root element of a tree representing the document. In HTML, :root represents the element and is identical to the selector html, except that its specificity is higher.
Using variable in the context
nav li:nth-of-type(1) {
background-color: var(--navColor1);
}
Note on the :nth-of-type, the :nth-of-type(n) selector matches every element that is the nth child, of a particular type, of its parent.
- Slide animation for the overlay
.overlay {
position: fixed;
z-index: 9;
left: 0;
top: 0;
width: 100vw;
height: 100vh;
background-color: rgba(0, 0, 0, 0.7);
transform: translateX(-100vw);
}
.overlay-slide-right {
transition: all 0.4s ease-in-out;
transform: translateX(0);
}
.overlay-slide-left {
transition: all 0.8s ease-in-out;
transform: translateX(-100vw);
}
- Slide in animation with delay for each navigation item
.slide-in-1 {
animation: slide-in 0.4s linear 0.2s both;
}
.slide-in-2 {
animation: slide-in 0.4s linear 0.4s both;
}
@keyframes slide-in {
from {
transform: translateX(-100%);
}
to{
transform: translateX(0);
}
}