简体   繁体   English

CSS隐藏所有元素,但带有某些子元素的元素除外

[英]CSS hide all elements, except one with certain child

I have this element here: 我在这里有这个要素:

#ihf-main-container .col-xs-6

I want to hide all the .col-xs-6 inside #ihf-main-container , except the .col-xs-6 element that has .ihf-for-sale-price inside of it....How would I accomplish this? 我想将所有.col-xs-6隐藏在#ihf-main-container ,除了其中的.col-xs-6元素,其中包含.ihf-for-sale-price ....我将如何完成这个?

Like Phiter says, there's no css selector for this case yet. 就像Phiter所说的,这种情况下还没有CSS选择器。 A parent selector will be available in CSS4. 父选择器在CSS4中可用。

  • For now, I would suggest to add an extra class to the .col-xs-6 element and hide them by that class. 现在,我建议向.col-xs-6元素添加一个额外的类,并按该类隐藏它们。
  • Don't show them at all by the use of the serverside script you're using (nicest way I think) 不要通过使用您正在使用的服务器端脚本来显示它们(我认为是最好的方式)
  • Or use javascript (for the JS libary jQuery it can be something $(".ihf-for-sale-price").parent().hide(); ) 或使用javascript(对于JS库jQuery,它可以是$(".ihf-for-sale-price").parent().hide();

I don't quite understand exactly but you could just name your last column as 我不太清楚,但是您可以将最后一列命名为

  <....  class="col-xs-6  newName" > in html

And then in css you could do 然后在css中你可以做

  .col-xs-6{
    display = none;
    }
   .newName{
   display = block;
   }

Hope this works but I feel I could help you better if you could add some pseudo code with the question. 希望这能奏效,但我想如果您可以在问题中添加一些伪代码,我会为您提供更好的帮助。

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

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