Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
133 views
in Technique[技术] by (71.8m points)

css - Is there a way to hide an element from another react component?

I'm fairly new to react and css and I'm a bit stuck. I have an animated NavBar that opens on a button click and fills the page - however, because of the way my app is structured I'm struggling to hide the component underneath the nav - i.e. home page, as elements with properties like position: absolute aren't being hidden underneath it.

Right now, my css classes for this are:

.nav-links.open {
    clip-path: circle(1400px at 95% -10%);
    -webkit-clip-path: circle(1400px at 95% -10%);
    opacity: 1;
  }

  .nav-links.close {
    clip-path: circle(100px at 95% -10%);
    -webkit-clip-path: circle(100px at 95% -10%);
    opacity: 0.7;
  }

And I simply toggle the classes with this:

toggleNavbar() {
    if (this.state.navBarActive === false) {
      this.setState({
        navBackStyle: 'white',
        navClass: 'nav-links open',
        navBarActive: !this.state.navBarActive,
      });
    } else {
      this.setState({
        navBackStyle: '#5b78c7',
        navClass: 'nav-links close',
        navBarActive: !this.state.navBarActive,
      });
    }
  }

My react components are all in the app.js, with a components folder containing the navbar, home etc.

My css files are also structured as components and imported with scss. I understand I could have everything in one file to make it easier to hide other elements but that won't be very easy to work with, as this is big project.

question from:https://stackoverflow.com/questions/66061617/is-there-a-way-to-hide-an-element-from-another-react-component

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...