简体   繁体   English

如何在不使用 jquery 或 js 的情况下应用条件 css

[英]how to apply conditional css without using jquery or js in react

I have a code like this我有这样的代码

<div class="abc">
    <componentName > abc </componentName>
    <component2> </component2> 
</div>

component2 is getting values from DB, and I want when component2 doesn't get any value, I want it to be hidden or display: none. component2 正在从 DB 中获取值,我希望当 component2 没有得到任何值时,我希望它被隐藏或显示:无。 But I've to do it using via CSS only and I can't add any class in components, I cant use JS, react, or jquery.但我只能通过 CSS 使用它,我不能在组件中添加任何 class,我不能使用 JS、反应或 jquery。 Any workaround will be helpful.任何解决方法都会有所帮助。

For now, when it's empty I have applied display: none;现在,当它为空时,我已应用display: none; there when it's empty or do not have any value.当它为空或没有任何价值时。 Play by putting values in it and make it empty again.通过将值放入其中并再次使其为空来进行游戏。 or you can also check the CSS by inspecting the element或者您也可以通过检查元素来检查 CSS

 componenet2:empty { display: none; }
 <div class="abc"> <componentName > abc </componentName> <componenet2></componenet2> </div>

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

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