I am creating a project where the navigation bar style changes according to the device type [PC/Mobile] but I don’t know how to change the CSS method
according to this website we can do it but it’s using the old version of react and when I tried in mine then its full of error
So, my code:
I need to animate that <div className="mobileMode">
JavaScript
x
28
28
1
import React from 'react';
2
import {Link} from 'react-router-dom';
3
import "./NavigationStyle.css"
4
function NavigationBar(){
5
return(
6
<nav>
7
<div className="mobileMode">
8
<div className="line"></div>
9
<div className="line"></div>
10
<div className="line"></div>
11
</div>
12
<ul>
13
<Link className="navLink" to="/">
14
<li>Home</li>
15
</Link>
16
<Link className="navLink" to="/myprojects">
17
<li>Projects</li>
18
</Link>
19
<Link className="navLink" to="/contact">
20
<li>Contact</li>
21
</Link>
22
</ul>
23
</nav>
24
)
25
}
26
27
export default NavigationBar;
28
and the css part: See I need to animate onClick to that .navLink.open
and that li.fade
I Have got this code from YouTube
JavaScript
1
37
37
1
// -- Code --
2
3
@media screen and (max-width:510px){
4
// -- Code --
5
.navLink{
6
position: fixed;
7
background-color: rgb(44, 44, 44);
8
width: 100%;
9
height: 100vh;
10
flex-direction: column;
11
clip-path: circle(100px at 90% -10%);
12
-webkit-clip-path: circle(100px at 90% -10%);
13
transition: all 1s ease-out;
14
color: rgb(226, 241, 255);
15
}
16
.navLink.open{
17
clip-path: circle(900px at 90% -10%);
18
-webkit-clip-path: circle(900px at 90% -10%);
19
pointer-events: all;
20
}
21
.navLink li{
22
opacity: 0;
23
}
24
.navLink li:nth-child(1){
25
transition: all 0.5s ease 0.2s;
26
}
27
.navLink li:nth-child(2){
28
transition: all 0.5s ease 0.2s;
29
}
30
.navLink li:nth-child(3){
31
transition: all 0.5s ease 0.2s;
32
}
33
li.fade{
34
opacity: 1;
35
}
36
}
37
whole code is there at: Github
Advertisement
Answer
The problem was where you placed style with the clip-path
option. You have specified for each child .navLink, but must be a parent ul.
I’m did replicate in the sandbox. example
JavaScript
1
28
28
1
ul {
2
display: flex;
3
height: 100%;
4
justify-content: space-around;
5
align-items: center;
6
margin-left: auto;
7
width: 50%;
8
}
9
10
@media screen and (max-width: 510px) {
11
ul {
12
display: flex;
13
position: fixed;
14
background-color: rgb(44, 44, 44);
15
width: 100%;
16
height: 100vh;
17
flex-direction: column;
18
clip-path: circle(30px at 95% 2%);
19
-webkit-clip-path: circle(30px at 95% 2%);
20
transition: all 1s ease-out;
21
}
22
ul.open {
23
clip-path: circle(150vh at 90% -10%);
24
-webkit-clip-path: circle(150vh at 90% -10%);
25
pointer-events: all;
26
}
27
}
28