我从外部源获取 HTML 并且无法更改代码,因此为了获得我们需要的结果,我需要有条件地隐藏内容。
在此示例中,我需要display:none
在 h2 上设置 level-0 和 level-1(在本例中为财务)。
<section class="level-0">
<h2 id="4001567002">Finance</h2>
<section class="child level-1">
<h2 id="4008036002">Fusion</h2>
<div class="opening" department_id="4001567002,4008036002" office_id="4000758002" data-office-4000758002="true" data-department-4001567002="true" data-department-4008036002="true">
<a data-mapped="true" target="_top" href="google.com">Business Systems Executive</a>
<br>
<span class="location">Sydney</span>
</div>
</section>
可能没有 level-1 在这种情况下 level-0 标头应该可见:
<section class="level-0">
<h2 id="4008036002">Fusion</h2>
<div class="opening" department_id="4001567002,4008036002" office_id="4000758002" data-office-4000758002="true" data-department-4001567002="true" data-department-4008036002="true">
<a data-mapped="true" target="_top" href="google.com">Business Systems Executive</a>
<br>
<span class="location">Sydney</span>
</div>
id 是不可预测的,所以我不能基于此隐藏级别。
这在纯 CSS 中是否可行,还是我应该想出另一个解决方案?