没有表格的剥离行-div内的子级div

时间:2019-04-18 13:19:26

标签: html css css3 bootstrap-4 css-selectors

我想删除带有“复杂”子级的行。我不知道该怎么做。 我使用引导程序,不确定是否会有所不同,我想没有;)

这是我的工作: https://jsfiddle.net/1w9tv4ce/2/ 我希望所有test-01都为绿色,然后为test-02黑色,test-03绿色,test-04黑色。

.rows-search div:nth-child(even) {
  background-color: #95CA44;
}

.rows-search div:nth-child(odd) {
  background-color: black;
}

.search-light-grey {
  color: darkgray;
}
<div class="container search-light-grey">
  <div class="rows-search">
    <div id="1">
      test-01
      <div>
        1
      </div>
      <div>
        <div>
          2a
        </div>
        <div>
          2b
        </div>
        <div>
          2c
        </div>
      </div>
    </div>
    <div id="2">test-02</div>
    <div id="3">test-03</div>
    <div id="4">test-04</div>
  </div>
</div>

非常感谢!

2 个答案:

答案 0 :(得分:2)

在选择器中使用子组合器(>)(这将仅针对立即子元素)-请参见以下演示:

private
.rows-search > div:nth-child(even) { /* <-- changed */
  background-color: #95CA44;
}

.rows-search > div:nth-child(odd) { /* <-- changed */
  background-color: black;
}

.search-light-grey {
  color: darkgray;
}

答案 1 :(得分:2)

根据我的评论,使用final ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new DefaultScalaModule()); final Child alice = new Child("Alice"); final List<Child> children = new ArrayList<>(); children.add(alice); final String bobString = mapper.writeValueAsString( new Parent("Bob", JavaConversions.asScalaBuffer(children).toList())); System.out.println(bobString); final Parent bob = mapper.readValue(bobString, Parent.class); System.out.println(bob); 选择器-表示直子

https://developer.mozilla.org/en-US/docs/Web/CSS/Child_combinator

>
.rows-search > div:nth-child(even) {
  background-color: #95CA44;
}

.rows-search > div:nth-child(odd) {
  background-color: black;
}

.search-light-grey {
  color: darkgray;
}