简体   繁体   English

如何在一个css文件中隐藏div但在另一个css文件中显示

[英]How to hide div in one css file but show it in another css file

I have a basic front end auth login react component page that loads when the page is first rendered.我有一个基本的前端身份验证登录反应组件页面,该页面在首次呈现页面时加载。 upon successful login:登录成功后:

  • it renders the app component.它呈现应用程序组件。
  • I have a login.css file and a app.css file.我有一个 login.css 文件和一个 app.css 文件。
  • in my html document i had to add code for a form to submit some user input for the app side of things.在我的 html 文档中,我必须为表单添加代码,以便为应用程序端提交一些用户输入。 I do not want this form to appear on the login side of things just once the app side has rendered.我不希望此表单仅在应用程序端呈现后出现在事物的登录端。
  • On the div classname I have tried visibility hidden in login.css and visibility:visible in app.css .在 div 类名上,我尝试了visibility hiddenlogin.cssvisibility:visibleapp.css中的可见性。
  • I have tried opacity:0 in login.css and opacity:100 in app.css.我在 login.css 中尝试了opacity:0 ,在 app.css 中尝试了opacity:100 as well as some other trouble shooting css that didn't work.以及其他一些不起作用的故障排除CSS。
  • It appears the login.css is overriding the app.css no matter what.无论如何, login.css似乎都覆盖了app.css

I am new to this so sorry if this is a dumb question just really need some help thank you in advance.我是新手,如果这是一个愚蠢的问题,我真的很抱歉,真的需要一些帮助,提前谢谢你。

To directly address your question, the CSS property you want to be using is display and set it to none .要直接解决您的问题,您要使用的 CSS 属性是display并将其设置为none If that still doesn't seem to work, check the specificity of your selector and verify that you're selecting the intended element.如果这似乎仍然不起作用,请检查选择器的特异性并验证您是否选择了预期的元素。 As a last resort use !important in your attribute to override all styles.作为最后的手段,在您的属性中使用!important来覆盖所有样式。

Since you're using React though, I highly recommend that you don't depend on CSS for this but rather use conditional rendering, eg由于您使用的是 React,我强烈建议您不要依赖 CSS,而是使用条件渲染,例如

return (
  <div>
    {loggedIn ? (
      User dashboard or whatever...
    ) : (
      Display login form
    )}
  </div>
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM