简体   繁体   English

将样式应用于未选中的元素

[英]Apply style to elements not selected

Currently, I have two rows of items set up, one of people and one of things: 当前,我设置了两行项目,其中一人,其中一件事:

person1 thing1 person2 thing2 person3 thing3 人1物1人2物2人3物3

When a user clicks on a person, that person and it's associated things will stay as they were, but every other item will fade (say, with an opacity of .4). 当用户单击某个人时,该人及其相关的事物将保持原样,但其他所有项都会消失(例如,不透明度为.4)。 When nothing is selected, everything is highlighted - that is to say, everything has an opacity of 1). 如果未选择任何内容,则将突出显示所有内容,也就是说,所有内容的不透明度为1)。 So, when you click on an item, it and it's friends will be highlighted. 因此,当您单击某个项目时,该项目及其好友将突出显示。

I understand the javscript behind events and applying classes, so: using css, is there an efficient way to do this? 我了解事件和应用类背后的琐事,因此:使用CSS,是否有一种有效的方法来做到这一点?

I understand that there is an inefficient solution - style each of the unselected items - but, is there something that will allow me to: 我知道有一个低效的解决方案-为每个未选中的项目设置样式-但是,有什么可以让我:

  1. Change only the active items 仅更改活动项目

  2. Have the styling information contained in a class (ie not as inline styling) 在类中包含样式信息(即不作为内联样式)

While writing the question I came up with a solution, though it's not as clean as I'd like. 在写问题时,我想出了一个解决方案,尽管它不是我想要的那么干净。

When an item is selected, add a class of .hasSelected to the container that holds all the list items. 选择一个项目后,将.hasSelected类添加到保存所有列表项的容器中。 Then, the css would be as follows: 然后,css将如下所示:

.hasSelected {
  .item {
    opacity: 0.4;
  }
  .item.selected {
    opacity: 1;
  }
}

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

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